From 84d8f291aee3afe5456af7e59f1219b3bb2f7f6f Mon Sep 17 00:00:00 2001 From: alessiaortile Date: Mon, 29 May 2023 16:58:25 +0200 Subject: [PATCH 01/36] AUV e SV module --- DESERT_Addons/uwauv/Makefile.am | 51 ++++ DESERT_Addons/uwauv/configure.ac | 69 ++++++ DESERT_Addons/uwauv/initlib.cc | 89 +++++++ DESERT_Addons/uwauv/uwauv-init.tcl | 111 +++++++++ DESERT_Addons/uwauv/uwauv-module.cc | 313 +++++++++++++++++++++++++ DESERT_Addons/uwauv/uwauv-module.h | 194 +++++++++++++++ DESERT_Addons/uwauv/uwauv-packet.h | 174 ++++++++++++++ DESERT_Addons/uwauv/uwauvctr-module.cc | 273 +++++++++++++++++++++ DESERT_Addons/uwauv/uwauvctr-module.h | 206 ++++++++++++++++ 9 files changed, 1480 insertions(+) create mode 100644 DESERT_Addons/uwauv/Makefile.am create mode 100644 DESERT_Addons/uwauv/configure.ac create mode 100644 DESERT_Addons/uwauv/initlib.cc create mode 100644 DESERT_Addons/uwauv/uwauv-init.tcl create mode 100644 DESERT_Addons/uwauv/uwauv-module.cc create mode 100644 DESERT_Addons/uwauv/uwauv-module.h create mode 100644 DESERT_Addons/uwauv/uwauv-packet.h create mode 100644 DESERT_Addons/uwauv/uwauvctr-module.cc create mode 100644 DESERT_Addons/uwauv/uwauvctr-module.h diff --git a/DESERT_Addons/uwauv/Makefile.am b/DESERT_Addons/uwauv/Makefile.am new file mode 100644 index 00000000..98797b60 --- /dev/null +++ b/DESERT_Addons/uwauv/Makefile.am @@ -0,0 +1,51 @@ +# +# Copyright (c) 2007 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 uwauv-tracer.cc uwauv-module.h uwauverror-module.h uwauv-packet.h uwauvctr-module.cc uwauvctrer-module.cc uwauvctr-tracer.cc uwauvctr-module.h uwauvctrer-module.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/configure.ac b/DESERT_Addons/uwauv/configure.ac new file mode 100644 index 00000000..92b0acc1 --- /dev/null +++ b/DESERT_Addons/uwauv/configure.ac @@ -0,0 +1,69 @@ +# +# 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_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..66d40aaa --- /dev/null +++ b/DESERT_Addons/uwauv/initlib.cc @@ -0,0 +1,89 @@ +// +// 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 initlib.cc + * @author Filippo Campagnaro, 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/uwauv-init.tcl b/DESERT_Addons/uwauv/uwauv-init.tcl new file mode 100644 index 00000000..c1c14d8c --- /dev/null +++ b/DESERT_Addons/uwauv/uwauv-init.tcl @@ -0,0 +1,111 @@ +# +# 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 uwauv-defaults.tcl +# @author Filippo Campagnaro 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_ 0 +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_ 0 +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_ 500 +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_ 1 +Module/UW/AUV/CER set drop_out_of_order_ 0 +Module/UW/AUV/CER set adaptiveRTO_ 0 + +Module/UW/AUV/CER instproc init {args} { + $self next $args + $self settag "UW/AUV/CER" +} + +#Module/UW/TDMA set slot_status 0 +#Module/UW/TDMA set num_hosts 2 +#Module/UW/TDMA set host_id 2 +#Module/UW/TDMA set frame_time 10 +#Module/UW/TDMA set guard_time 1 +#Module/UW/TDMA set slot_duration 4 + +#Module/UW/TDMA instproc init {args} { +# $self next $args +# $self settag "UW/TDMA" +#} + +Position/UWSM 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..76dc76e7 --- /dev/null +++ b/DESERT_Addons/uwauv/uwauv-module.cc @@ -0,0 +1,313 @@ +// +// 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 uwauv-module.cc +* @author Filippo Campagnaro, 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_flag(0) + , out_file_stats(0) +{ + UWSMPosition p = UWSMPosition(); + posit=&p; + bind("ackTimeout_", (int*) &ackTimeout); + bind("ackPriority_", (int*) &ackPriority); + bind("drop_old_waypoints_", (int*) &drop_old_waypoints); + bind("log_flag_", (int*) &log_flag ); + if (ackTimeout < 0) { + cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" + << std::endl; + ackTimeout = 10; + } + +} + +UwAUVModule::UwAUVModule(UWSMPosition* p) + : UwCbrModule() + , last_sn_confirmed(0) + , ack(0) + , ackPolicy(ACK_PIGGYBACK) + , ackTimeout(10) + , ackTimer_(this) + , ackPriority(0) + , ackNotPgbk(0) + , drop_old_waypoints(0) + , log_flag(0) + , out_file_stats(0) +{ + posit = p; + bind("ackTimeout_", (int*) &ackTimeout); + bind("ackPriority_", (int*) &ackPriority); + bind("drop_old_waypoints_", (int*) &drop_old_waypoints); + bind("log_flag_", (int*) &log_flag ); + if (ackTimeout < 0) { + cerr << NOW << " Invalide ACK timout < 0, timeout set to 10 by defaults" + << std::endl; + ackTimeout = 10; + } + + +} + +UwAUVModule::~UwAUVModule() {} + +void UwAUVModule::setPosition(UWSMPosition* 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) { + UWSMPosition* p = dynamic_cast (tcl.lookup(argv[2])); + posit=p; + tcl.resultf("%s", "position Setted\n"); + return TCL_OK; + } + 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; + } + } + 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(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; + } + } + return UwCbrModule::command(argc,argv); +} + +void UwAUVModule::initPkt(Packet* p) { + hdr_uwAUV_monitoring* uwAUVh = HDR_UWAUV_MONITORING(p); + //hdr_uwAUV_ctr* uwAUVh = HDR_UWAUV_CTR(p); + hdr_uwcbr *uwcbrh = HDR_UWCBR(p); + uwAUVh->x() = posit->getX(); + uwAUVh->y() = posit->getY(); + uwAUVh->z() = posit->getZ(); + //uwAUVh->speed() = 200; + + //uwAUVh->ack() = ack; + + 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, Handler* h) { + recv(p); +} + +void UwAUVModule::recv(Packet* p) { + + hdr_uwAUV_ctr* uwAUVh = HDR_UWAUV_CTR(p); + + if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { //obsolete packets + if (debug_) { + std::cout << NOW << " UwAUVModule::old waypoint with sn " + << uwAUVh->sn() << " dropped " << std::endl; + } + + } else { //packet in order + posit->setdest(uwAUVh->x(),uwAUVh->y(),uwAUVh->z(),uwAUVh->speed()); + last_sn_confirmed = uwAUVh->sn(); + } + + ack = last_sn_confirmed+1; + priority_ = (char) ackPriority; + + if (log_flag == 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) { + + if (ackPriority == 0) { + UwCbrModule::sendPkt(); + if (debug_) + cout << NOW << " ACK sent immediately with standard priority " + << std::endl; + } else { + UwCbrModule::sendPktHighPriority(); + if (debug_) + cout << NOW << " ACK sent immediately with high priority " + << std::endl; + } + } + + if (ackPolicy == ACK_PGBK_OR_TO) { + ackTimer_.resched(ackTimeout); + } +} + +void UwAUVModule::sendAck() { + ackNotPgbk++; + if (ackPriority == 0) { + UwCbrModule::sendPkt(); + if (debug_) + cout << NOW << " ACK timeout expired, ACK sent with standard " + << "priority " << std::endl; + } else { + UwCbrModule::sendPktHighPriority(); + if (debug_) + 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..c5a933e8 --- /dev/null +++ b/DESERT_Addons/uwauv/uwauv-module.h @@ -0,0 +1,194 @@ +// +// 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 uwauv-module.h +* @author Filippo Campagnaro Alessia Ortile +* @version 1.0.0 +* +* \brief Provides the definition of the class UWAUV. +* +* Provides the definition of the class UWAUV, based on UwCbr. +* UWAUV can manage no more than 2^16 packets. If a module generates more +* than 2^16 packets, they will be dropped, according with UwCbr. +* UWAUV sends periodically monitoring packets containing information about +* the current position and acknowledges the last control packet received. +* Each control packet contains the next waypoint that has to be reach. +*/ + +#ifndef UWAUV_MODULE_H +#define UWAUV_MODULE_H +#include +#include +#include "uwsmposition.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. */ +#define HDR_UWAUV_MONITORING(p) (hdr_uwAUV_monitoring::access(p)) +#define HDR_UWAUV_CTR(p) (hdr_uwAUV_ctr::access(p)) + +using namespace std; + +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 UWSMPosition* p Pointer to the AUV position + */ + UwAUVModule(UWSMPosition* 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*); + + /** + * Performs the reception of packets from upper and lower layers. + * + * @param Packet* Pointer to the packet will be received. + * @param Handler* Handler. + */ + virtual void recv(Packet* p, Handler* h); + + /** + * Sets the position of the AUV + * + * @param UWSMPosition * p Pointer to the AUV position + */ + virtual void setPosition(UWSMPosition* p); + + /** + * Returns the position of the AUV + * + * @return the current AUV position + */ + inline UWSMPosition* getPosition() { 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 }; + + UWSMPosition* 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.*/ + //int send_ack_immediately; /**< Flag either to send acks immediately or not.*/ + 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.*/ + int ackTimeout; /**< Timeout after which ACK is sent if ackPolicy = ACK_PGBK_OR_TO. */ + UwAUVSendAckTimer ackTimer_; /**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_; + + + 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_; + } +} 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..138b55ee --- /dev/null +++ b/DESERT_Addons/uwauv/uwauvctr-module.cc @@ -0,0 +1,273 @@ +// +// 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 uwauvctr-module.cc +* @author Filippo Campagnaro +* @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 UwAUVModuleClass 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(UWSMPosition* p) + : UwCbrModule() + , sn(0) + , adaptiveRTO(0) + , adaptiveRTO_parameter(0.5) + //, sumrttAck(0) + //, rttAcksamples(0) +{ + posit=p; + speed=1; + bind("adaptiveRTO_", (int *) &adaptiveRTO); + if (adaptiveRTO == 1) { + 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) + //, sumrttAck(0) + //, rttAcksamples(0) +{ + p = NULL; + UWSMPosition p = UWSMPosition(); + posit=&p; + //posit = Position(); + speed = 1; + bind("adaptiveRTO_", (int *) &adaptiveRTO); + if (adaptiveRTO == 1) { + 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) { + UWSMPosition* p = dynamic_cast (tcl.lookup(argv[2])); + posit = p; + return TCL_OK; + } 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(UWSMPosition* p){ + posit = p; +} + +void UwAUVCtrModule::initPkt(Packet* p) { + if(this->p == NULL){ + hdr_uwAUV_ctr* uwAUVh = HDR_UWAUV_CTR(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(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(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, Handler* h) { + recv(p); +} + +void UwAUVCtrModule::recv(Packet* p) { + + hdr_uwAUV_monitoring* monitoring = HDR_UWAUV_MONITORING(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..5ca53ca4 --- /dev/null +++ b/DESERT_Addons/uwauv/uwauvctr-module.h @@ -0,0 +1,206 @@ +// +// 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 uwauvctr-module.h +* @author Filippo Campagnaro +* @version 1.0.0 +* +* \brief Provides the definition of the class UWAUV. +* +* Provides the definition of the class UWAUVCTR, based on UwCbr. +* UWAUVCTR can manage no more than 2^16 packets. If a module generates more +* than 2^16 packets, they will be dropped, according with UwCbr. +* UWAUVCTR sends control packets containing the next waypoint that has to be +* reach by a AUV. In addition it receives monitoring packets containing the current +* AUV position and acks of the sent packets. Whether the ack is not received, the +* control packet is resent, according to the priority. In particular, last waypoint +* transmitted has the highest priority, whereas the others are forgotten.: +*/ + +#ifndef UWAUV_CTR_MODULE_H +#define UWAUV_CTR_MODULE_H +#include +#include "uwauv-packet.h" +#include "uwsmposition.h" +#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. */ +#define HDR_UWAUV_MONITORING(p) (hdr_uwAUV_monitoring::access(p)) +#define HDR_UWAUV_CTR(p) (hdr_uwAUV_ctr::access(p)) +using namespace std; +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(UWSMPosition* 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(UWSMPosition* p); + + /** + * Returns the position of the AUVCtr + * + * @return the current AUVCtr position + */ + inline UWSMPosition* getPosition() { 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*); + + /** + * Performs the reception of packets from upper and lower layers. + * + * @param Packet* Pointer to the packet will be received. + * @param Handler* Handler. + */ + virtual void recv(Packet* p, Handler* h); + + /** + * 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: + + UWSMPosition* 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 From 385851f4d8bb7930592ce75a929f129d6b9f228b Mon Sep 17 00:00:00 2001 From: alessiaortile Date: Mon, 29 May 2023 16:59:41 +0200 Subject: [PATCH 02/36] AUV error application + simulation --- DESERT_Addons/uwauv/uwauvctr-tracer.cc | 75 +++ DESERT_Addons/uwauv/uwauvctrer-module.cc | 249 +++++++ DESERT_Addons/uwauv/uwauvctrer-module.h | 182 +++++ DESERT_Addons/uwauv/uwauverror-module.cc | 287 ++++++++ DESERT_Addons/uwauv/uwauverror-module.h | 182 +++++ .../DESERT/samples/desert_samples/AUV/auv.tcl | 167 +++++ .../DESERT/samples/desert_samples/AUV/suv.tcl | 159 +++++ .../AUV/test_uwmulti_traffic_auv.tcl | 621 ++++++++++++++++++ 8 files changed, 1922 insertions(+) create mode 100644 DESERT_Addons/uwauv/uwauvctr-tracer.cc create mode 100644 DESERT_Addons/uwauv/uwauvctrer-module.cc create mode 100644 DESERT_Addons/uwauv/uwauvctrer-module.h create mode 100644 DESERT_Addons/uwauv/uwauverror-module.cc create mode 100644 DESERT_Addons/uwauv/uwauverror-module.h create mode 100644 DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl create mode 100644 DESERT_Framework/DESERT/samples/desert_samples/AUV/suv.tcl create mode 100644 DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl diff --git a/DESERT_Addons/uwauv/uwauvctr-tracer.cc b/DESERT_Addons/uwauv/uwauvctr-tracer.cc new file mode 100644 index 00000000..6551be35 --- /dev/null +++ b/DESERT_Addons/uwauv/uwauvctr-tracer.cc @@ -0,0 +1,75 @@ +// +// 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. +// + +/** + * @file uwauvtct-tracer.cc + * @author Filippo Campagnaro + * @version 1.0.0 + * + * \brief Provides a tracer class for UWAUVCTR packets. + * + * Provides a tracer class for UWAUVCTR packets. + */ + + +#include "uwauvctr-module.h" + +/** + * Class that defines a tracer for hdr_uwAUV_ctr packets. + */ +class UWAUVCtrTracer : public Tracer { +public: + UWAUVCtrTracer(); +protected: + void format(Packet *p, SAP* sap); +}; + +UWAUVCtrTracer::UWAUVCtrTracer() : Tracer(4) { +} + +void UWAUVCtrTracer::format(Packet *p, SAP *sap) { + hdr_cmn *ch = hdr_cmn::access(p); + + if (ch->ptype() != PT_UWCBR) + return; + + hdr_uwAUV_ctr *uwAUVh = HDR_UWAUV_CTR(p); +} + +extern "C" int UwAUVCtrtracer_Init() { + SAP::addTracer(new UWAUVCtrTracer); + return 0; +} + +extern "C" int CyguwAUVCtrtracer_Init() { + UwAUVCtrtracer_Init(); + return 0; +} + + diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.cc b/DESERT_Addons/uwauv/uwauvctrer-module.cc new file mode 100644 index 00000000..76e92c3b --- /dev/null +++ b/DESERT_Addons/uwauv/uwauvctrer-module.cc @@ -0,0 +1,249 @@ +// +// 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 uwauvctrer-module.cc +* @author Filippo Campagnaro, 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; +/** +* Adds the module for UwAUVModuleClass in ns2. +*/ + +/** +* 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(UWSMPosition* p) + : UwCbrModule() + , ack(0) + , last_sn_confirmed(0) + , ackTimeout(10) + , drop_old_waypoints(1) + , log_flag(0) + , out_file_stats(0) +{ + posit=p; + speed=5; + bind("ackTimeout_", (int*) &ackTimeout); + bind("drop_old_waypoints_", (int*) &drop_old_waypoints); + bind("log_flag_", (int*) &log_flag ); + if (ackTimeout < 0) { + cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" + << std::endl; + ackTimeout = 10; + } +} + +UwAUVCtrErModule::UwAUVCtrErModule() + : UwCbrModule() + , ack(0) + , last_sn_confirmed(0) + , ackTimeout(10) + , drop_old_waypoints(1) + , log_flag(0) + , out_file_stats(0) + +{ + p = NULL; + UWSMPosition p = UWSMPosition(); + posit=&p; + //posit = Position(); + speed = 5; + bind("ackTimeout_", (int*) &ackTimeout); + bind("drop_old_waypoints_", (int*) &drop_old_waypoints); + bind("log_flag_", (int*) &log_flag ); + if (ackTimeout < 0) { + cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" + << std::endl; + ackTimeout = 10; + } + +} + +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) { + UWSMPosition* p = dynamic_cast (tcl.lookup(argv[2])); + posit = p; + return TCL_OK; + } else + if (strcasecmp(argv[1], "setSpeed") == 0) { + speed = 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 UwAUVCtrErModule::start() {} + +void UwAUVCtrErModule::setPosition(UWSMPosition* p){ + posit = p; +} + +void UwAUVCtrErModule::initPkt(Packet* p) { + + hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); + uwAUVh->ack() = ack; + + ack = 0; + + UwCbrModule::initPkt(p); + if (debug_) { + std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) setting last ack" + << std::endl; + } +} + +void UwAUVCtrErModule::recv(Packet* p, Handler* h) { + recv(p); +} + +void UwAUVCtrErModule::recv(Packet* p) { + + hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); + + if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { //obsolete packets + if (debug_) { + std::cout << NOW << " UwAUVCtrErrModule::old error with sn " + << uwAUVh->sn() << " dropped " << std::endl; + } + + } else { //packet in order + posit->setdest(uwAUVh->x(),uwAUVh->y(),uwAUVh->z(),uwAUVh->speed()); + last_sn_confirmed = uwAUVh->sn(); + } + + ack = last_sn_confirmed+1; + + if (log_flag == 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 << " UwAUVCtrErrModule::recv(Packet *p) SUV received new " + "error: X = " << uwAUVh->x() << ", Y = " << uwAUVh->y() + << ", Z = " << uwAUVh->z()<< std::endl; + } + UwCbrModule::recv(p); + + + UwCbrModule::sendPkt(); + if (debug_) + cout << NOW << " ACK sent immediately with standard priority " + << std::endl; + +} + diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.h b/DESERT_Addons/uwauv/uwauvctrer-module.h new file mode 100644 index 00000000..410ea1af --- /dev/null +++ b/DESERT_Addons/uwauv/uwauvctrer-module.h @@ -0,0 +1,182 @@ +// +// 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 uwauvctr-module.h +* @author Filippo Campagnaro +* @version 1.0.0 +* +* \brief Provides the definition of the class UWAUV. +* +* Provides the definition of the class UWAUVCTR, based on UwCbr. +* UWAUVCTR can manage no more than 2^16 packets. If a module generates more +* than 2^16 packets, they will be dropped, according with UwCbr. +* UWAUVCTR sends control packets containing the next waypoint that has to be +* reach by a AUV. In addition it receives monitoring packets containing the current +* AUV position and acks of the sent packets. Whether the ack is not received, the +* control packet is resent, according to the priority. In particular, last waypoint +* transmitted has the highest priority, whereas the others are forgotten.: +*/ + +#ifndef UWAUVError_MODULE_H +#define UWAUVError_MODULE_H +#include +#include "uwauv-packet.h" +#include "uwsmposition.h" +#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. */ +#define HDR_UWAUV_MONITORING(p) (hdr_uwAUV_monitoring::access(p)) +#define HDR_UWAUV_CTR(p) (hdr_uwAUV_ctr::access(p)) +#define HDR_UWAUV_ERROR(p) (hdr_uwAUV_error::access(p)) +using namespace std; +class UwAUVCtrModule; + + +/** +* 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(UWSMPosition* 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(UWSMPosition* p); + + /** + * Returns the position of the AUVCtr + * + * @return the current AUVCtr position + */ + inline UWSMPosition* getPosition() { return posit;} + + + /** + * Performs the reception of packets from upper and lower layers. + * + * @param Packet* Pointer to the packet will be received. + */ + virtual void recv(Packet*); + + /** + * Performs the reception of packets from upper and lower layers. + * + * @param Packet* Pointer to the packet will be received. + * @param Handler* Handler. + */ + virtual void recv(Packet* p, Handler* h); + + /** + * 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); } + + /** + * 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); } + + + +protected: + + UWSMPosition* posit; /**< Controller position.*/ + int last_sn_confirmed; + int ack; + int drop_old_waypoints; + 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 speed; /**< Moving speed sent to the AUV.*/ + int sn; /**Sequence number of the last control packet sent.*/ + Packet* p; + int log_flag; + std::ofstream out_file_stats; + int ackTimeout; + +}; + +#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..80c5abd1 --- /dev/null +++ b/DESERT_Addons/uwauv/uwauverror-module.cc @@ -0,0 +1,287 @@ +// +// 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 uwauv-module.cc +* @author Filippo Campagnaro, 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. +*/ +/** +* Adds the module for UwAUVModuleClass 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) + , ackPolicy(ACK_PIGGYBACK) + , ackTimeout(10) + , ackNotPgbk(0) + , drop_old_waypoints(0) + , log_flag(0) + , out_file_stats(0) +{ + UWSMPosition p = UWSMPosition(); + speed = 5; + posit=&p; + bind("ackTimeout_", (int*) &ackTimeout); + bind("drop_old_waypoints_", (int*) &drop_old_waypoints); + bind("log_flag_", (int*) &log_flag ); + if (ackTimeout < 0) { + cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" + << std::endl; + ackTimeout = 10; + } + +} + +UwAUVErrorModule::UwAUVErrorModule(UWSMPosition* p) + : UwCbrModule() + , last_sn_confirmed(0) + , sn(0) + , ackPolicy(ACK_PIGGYBACK) + , ackTimeout(10) + , ackNotPgbk(0) + , drop_old_waypoints(0) + , log_flag(0) + , out_file_stats(0) +{ + posit = p; + speed = 5; + bind("ackTimeout_", (int*) &ackTimeout); + bind("drop_old_waypoints_", (int*) &drop_old_waypoints); + bind("log_flag_", (int*) &log_flag ); + if (ackTimeout < 0) { + cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" + << std::endl; + ackTimeout = 10; + } + + +} + +UwAUVErrorModule::~UwAUVErrorModule() {} + +void UwAUVErrorModule::setPosition(UWSMPosition* 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(strcasecmp(argv[1], "getAckNotPgbk") == 0) { + tcl.resultf("%d", ackNotPgbk); + return TCL_OK; + } + } + else if(argc == 3){ + if (strcasecmp(argv[1], "setPosition") == 0) { + UWSMPosition* p = dynamic_cast (tcl.lookup(argv[2])); + posit=p; + tcl.resultf("%s", "position Setted\n"); + return TCL_OK; + } + 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; + } + } + if (strcasecmp(argv[1], "setAckTimeout") == 0) { + ackTimeout = 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(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; + } + } + return UwCbrModule::command(argc,argv); +} + +void UwAUVErrorModule::initPkt(Packet* p) { + + //hdr_uwAUV_ctr* uwAUVh = HDR_UWAUV_CTR(p); + hdr_uwcbr *uwcbrh = HDR_UWCBR(p); + + + if(this->p == NULL){ + random_device rd; + mt19937 generator(rd()); + uniform_real_distribution distrib(0.0, 1.0); + hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); + + double randomValue = distrib(generator) ; + + std::cout << NOW << " UwAUVErrorModule::r.v " + << randomValue<< std::endl; + + if(randomValue < 0.75){ + uwAUVh->x() = posit->getX(); + uwAUVh->y() = posit->getY(); + uwAUVh->z() = posit->getZ(); + uwAUVh->speed() = speed; + uwAUVh->sn() = ++sn; + this->p = p; + if (debug_) { + std::cout << NOW << " UwAUVErroModule::initPkt(Packet *p) " + << "ERROR!"<< std::endl; + } + } + } + else{ + hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); + uwAUVh->x() = posit->getX(); + uwAUVh->y() = posit->getY(); + uwAUVh->z() = posit->getZ(); + uwAUVh->speed() = speed; + uwAUVh->sn() = sn; + if (debug_) { + std::cout << NOW << " UwAUVErroModule::initPkt(Packet *p) " + << "Retransmitting"<< std::endl; + } + } + + if (debug_){ + hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); + std::cout << NOW << " UwAUVErrorModule::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 << " UwAUVErrorModule::sending packet with priority " + << (int)uwcbrh->priority() << std::endl; + } + //priority_ = 0; +} + +void UwAUVErrorModule::recv(Packet* p, Handler* h) { + recv(p); +} + +void UwAUVErrorModule::recv(Packet* p) { + + hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); + + if(uwAUVh->ack() == sn + 1) { + sendTmr_.force_cancel(); + this->p = NULL; + } + + + if(uwAUVh->ack() > 0 && debug_) + std::cout << NOW << " UwAUVErrorModule::recv(Packet *p) error ACK " + << "received " << uwAUVh->ack()<< std::endl; + else if((uwAUVh->ack())<0 && debug_) + std::cout << NOW << " UwAUVErrorModule::recv(Packet *p) error NACK " + <<"received"<< std::endl; + +} diff --git a/DESERT_Addons/uwauv/uwauverror-module.h b/DESERT_Addons/uwauv/uwauverror-module.h new file mode 100644 index 00000000..54c238b3 --- /dev/null +++ b/DESERT_Addons/uwauv/uwauverror-module.h @@ -0,0 +1,182 @@ +// +// 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 uwauv-module.h +* @author Filippo Campagnaro Alessia Ortile +* @version 1.0.0 +* +* \brief Provides the definition of the class UWAUVError. +* +* Provides the definition of the class UWAUVError, based on UwCbr. +* UWAUVError can manage no more than 2^16 packets. If a module generates more +* than 2^16 packets, they will be dropped, according with UwCbr. +* UWAUVError sends periodically monitoring packets containing information about +* the current position and acknowledges the last control packet received. +* Each control packet contains the next waypoint that has to be reach. +*/ + +#ifndef UWAUVError_MODULE_H +#define UWAUVError_MODULE_H +#include +#include +#include "uwsmposition.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. */ +#define HDR_UWAUV_MONITORING(p) (hdr_uwAUV_monitoring::access(p)) +#define HDR_UWAUV_CTR(p) (hdr_uwAUV_ctr::access(p)) +#define HDR_UWAUV_ERROR(p) (hdr_uwAUV_error::access(p)) + +using namespace std; + +class UwAUVErrorModule; + +/** +* UwAUVModule class is used to manage UWAUV packets and to collect statistics about them. +*/ +class UwAUVErrorModule : public UwCbrModule { +public: + + /** + * Default Constructor of UwAUVModule class. + */ + UwAUVErrorModule(); + + /** + * Constructor with position setting of UwAUVModule class. + * + * @param UWSMPosition* p Pointer to the AUV position + */ + UwAUVErrorModule(UWSMPosition* p); + + /** + * Destructor of UwAUVModule 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*); + + /** + * Performs the reception of packets from upper and lower layers. + * + * @param Packet* Pointer to the packet will be received. + * @param Handler* Handler. + */ + virtual void recv(Packet* p, Handler* h); + + /** + * Sets the position of the AUV + * + * @param UWSMPosition * p Pointer to the AUV position + */ + virtual void setPosition(UWSMPosition* p); + + /** + * Returns the position of the AUV + * + * @return the current AUV position + */ + inline UWSMPosition* getPosition() { 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 }; + + UWSMPosition* posit; /**< AUV position.*/ + float speed; + int last_sn_confirmed;/**< Sequence number of the last command Packete received.*/ + int sn; /**< If not zero, contains the ACK to the last command Packete received.*/ + //int send_ack_immediately; /**< Flag either to send acks immediately or not.*/ + 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.*/ + int ackTimeout; /**< Timeout after which ACK is sent if ackPolicy = ACK_PGBK_OR_TO. */ + 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_flag; /**< Flag to enable log file writing.*/ + Packet* p; + + std::ofstream out_file_stats; /**< Output stream for the textual file of debug */ +}; + +#endif // UWAUVError_MODULE_H 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..64a57507 --- /dev/null +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl @@ -0,0 +1,167 @@ +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 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 --> SUV + 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(auv_period) + Module/UW/AUV set PoissonTraffic_ 1 + Module/UW/AUV set traffic_type_ 1 + Module/UW/AUV set debug_ 0 + set auv_app($id) [new Module/UW/AUV] + + # TRAFFICO 2: CONTROL:SUV --> AUV + #Module/UW/ROV/CTR set packetSize_ $opt(pktsize_control) + #Module/UW/ROV/CTR set period_ $opt(cbr_period_control) + #Module/UW/ROV/CTR set PoissonTraffic_ 1 + #Module/UW/ROV/CTR set traffic_type_ 2 + # Module/UW/CBR set debug_ 0 + #set cbr2_auv($id) [new Module/UW/ROV/CTR] + + # TRAFFICO 3: ERROR AUV --> SUV + 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(auv_period) + Module/UW/AUV/ERR set PoissonTraffic_ 1 + Module/UW/AUV/ERR set traffic_type_ 3 + Module/UW/AUV/ERR set debug_ 1 + 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 + set ctr_auv($id) [new Module/UW/MULTI_TRAFFIC_RANGE_CTR] + + + Module/UW/TDMA set frame_duration $opt(tdma_frame) + Module/UW/TDMA set fair_mode 1 + Module/UW/TDMA set guard_time $opt(tdma_gard) + Module/UW/TDMA set tot_slots $opt(n_auv) + Module/UW/TDMA set debug_ 0 + Module/UW/TDMA set queue_size_ 100 + + 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] + 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 $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/UWSM"] ; #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/suv.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/suv.tcl new file mode 100644 index 00000000..70b7c379 --- /dev/null +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/suv.tcl @@ -0,0 +1,159 @@ +set scr [info script] +proc createSUV { id } { + + global ns suv_app suv_err position_suv node_suv udp_suv + global portnum_suv portnum2_suv ipr_suv ipif_suv + global channel channel_op propagation propagation_op data_mask data_mask_op + global phy_suv posdb_suv opt rvposx mll_suv mll_op_suv mac_suv + global mac_op_suv db_manager node_suv_coordinates + + set node_suv [$ns create-M_Node $opt(tracefile) $opt(cltracefile)] + + # TRAFFICO 2: CONTROL: SUV --> AUV + Module/UW/AUV/CTR set packetSize_ $opt(pktsize) + Module/UW/AUV/CTR set period_ $opt(ctr_period) + Module/UW/AUV/CTR set PoissonTraffic_ 1 + 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 suv_app($id1) [new Module/UW/AUV/CTR] + } + + # TRAFFICO 3: ERROR: AUV --> SUV + Module/UW/AUV/CER set packetSize_ $opt(pktsize) + Module/UW/AUV/CER set period_ $opt(ctr_period) + Module/UW/AUV/CER set PoissonTraffic_ 1 + Module/UW/AUV/CER set traffic_type_ 3 + Module/UW/AUV/CER set debug_ 1 + for {set id1 0} {$id1 <= $opt(n_auv)} {incr id1} { + set suv_err($id1) [new Module/UW/AUV/CER] + } + + set udp_suv [new Module/UW/UDP] + set ipr_suv [new Module/UW/StaticRouting] + set ipif_suv [new Module/UW/IP] + + set ctr_suv [new Module/UW/MULTI_TRAFFIC_RANGE_CTR] + + set mll_suv [new Module/UW/MLL] + set mac_suv [new Module/UW/CSMA_ALOHA] + Module/UW/PHYSICAL set BitRate_ $opt(bitrate) + Module/UW/PHYSICAL set MaxTxSPL_dB_ $opt(txpower) + set phy_suv [new Module/UW/PHYSICAL] + $mll_suv setstackid 1 + + set mll_op_suv [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_suv [new Module/UW/CSMA_ALOHA] + set phy_op_suv [new Module/UW/OPTICAL/PHY] + + #$node_suv addModule 8 $cbr_suv 0 "CBR1" + for {set id1 0} {$id1 <= $opt(n_auv)} {incr id1} { + #$node_suv addModule 8 $cbr_suv($id1) 0 "CBR1" + $node_suv addModule 8 $suv_app($id1) 0 "CBR1" + $node_suv addModule 8 $suv_err($id1) 0 "CBR2" + } + #$node_suv addModule 8 $cbr3_suv 0 "CBR3" + $node_suv addModule 7 $udp_suv 0 "UDP1" + $node_suv addModule 6 $ipr_suv 0 "IPR1" + $node_suv addModule 5 $ipif_suv 2 "IPF1" + + $node_suv addModule 4 $ctr_suv 2 "CTR" + + $node_suv addModule 3 $mll_suv 2 "MLL_LF" + $node_suv addModule 2 $mac_suv 2 "MAC_LF" + $node_suv addModule 1 $phy_suv 0 "PHY_LF" + + $node_suv addModule 3 $mll_op_suv 2 "MLL_OP" + $node_suv addModule 2 $mac_op_suv 2 "MAC_OP" + $node_suv addModule 1 $phy_op_suv 0 "PHY_OP" + + #$node_suv setConnection $cbr_suv $udp_suv 0 + for {set id1 0} {$id1 <= $opt(n_auv)} {incr id1} { + #$node_suv setConnection $cbr_suv($id1) $udp_suv 0 + $node_suv setConnection $suv_app($id1) $udp_suv 0 + $node_suv setConnection $suv_err($id1) $udp_suv 0 + } + #$node_suv setConnection $cbr3_suv $udp_suv 0 + $node_suv setConnection $udp_suv $ipr_suv 0 + $node_suv setConnection $ipr_suv $ipif_suv 2 + $node_suv setConnection $ipif_suv $ctr_suv 2 + + $node_suv setConnection $ctr_suv $mll_suv 2 + $node_suv setConnection $mll_suv $mac_suv 2 + $node_suv setConnection $mac_suv $phy_suv 2 + $node_suv addToChannel $channel $phy_suv 0 + + $node_suv setConnection $ctr_suv $mll_op_suv 2 + $node_suv setConnection $mll_op_suv $mac_op_suv 2 + $node_suv setConnection $mac_op_suv $phy_op_suv 2 + $node_suv addToChannel $channel_op $phy_op_suv 0 + + + + for {set id1 0} {$id1 <= $opt(n_auv)} {incr id1} { + #set portnum_suv($id1) [$udp_suv assignPort $cbr_suv($id1) ] + set portnum_suv($id1) [$udp_suv assignPort $suv_app($id1) ] + set portnum2_suv($id1) [$udp_suv assignPort $suv_err($id1) ] + } + #set portnum3_suv [$udp_suv assignPort $cbr3_suv ] + + if {$id > 254} { + puts "hostnum > 254!!! exiting" + exit + } + set tmp_ [expr $id + 1] + $ipif_suv addr $tmp_ + + set position_suv [new "Position/BM"] + $node_suv addPosition $position_suv + set posdb_suv [new "PlugIn/PositionDB"] + $node_suv addPlugin $posdb_suv 20 "PDB" + $posdb_suv addpos [$ipif_suv addr] $position_suv + + 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_suv setPropagation $propagation + $phy_suv setSpectralMask $data_mask + $phy_suv setInterference $interf_data + + $phy_op_suv setPropagation $propagation_op + $phy_op_suv setSpectralMask $data_mask_op + $phy_op_suv setInterference $interf_data_op + # $phy_op_leader useLUT + + $mac_suv $opt(ack_mode) + $mac_suv setMacAddr $tmp_ + $mac_suv initialize + + + $mac_op_suv setMacAddr $tmp_ + $mac_op_suv $opt(ack_mode) + $mac_op_suv initialize + +# MONITORING TRAFFIC + $ctr_suv addRobustLowLayer 1 "MLL_LF" + $ctr_suv addFastLowLayer 1 "MLL_OP" + $ctr_suv addUpLayer 1 "IPF1" + $ctr_suv setBufferFeatures 1 1000 0 + +# CONTROL TRAFFIC + $ctr_suv addRobustLowLayer 2 "MLL_LF" + $ctr_suv addFastLowLayer 2 "MLL_OP" + $ctr_suv addUpLayer 2 "IPF1" + $ctr_suv setBufferFeatures 2 1000 0 + +# #ERROR TRAFFIC + $ctr_suv addRobustLowLayer 3 "MLL_LF" + $ctr_suv addFastLowLayer 3 "MLL_OP" + $ctr_suv addUpLayer 3 "IPF1" + $ctr_suv setBufferFeatures 3 1000 0 + +} \ No newline at end of file diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl new file mode 100644 index 00000000..4e344418 --- /dev/null +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl @@ -0,0 +1,621 @@ +# +# 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: Giovanni Toso +# 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 depicts a very simple but complete stack in which two node_leaders send data +# to a common sink. The second node_leader is used by the first one as a relay to send data to the sink. +# The routes are configured by using UW/STATICROUTING. +# The application used to generate data is UW/CBR. +# ---------------------------------------------------------------------------------- +# Stack +# Node 1 Node 2 Sink +# +--------------------------+ +--------------------------+ +-------------+------------+ +# | 7. UW/CBR | | 7. UW/CBR | | 7. UW/CBR | UW/CBR | +# +--------------------------+ +--------------------------+ +-------------+------------+ +# | 6. UW/UDP | | 6. UW/UDP | | 6. UW/UDP | +# +--------------------------+ +--------------------------+ +--------------------------+ +# | 5. UW/STATICROUTING | | 5. UW/STATICROUTING | | 5. UW/STATICROUTING | +# +--------------------------+ +--------------------------+ +--------------------------+ +# | 4. UW/IP | | 4. UW/IP | | 4. UW/IP | +# +--------------------------+ +--------------------------+ +--------------------------+ +# | 3. UW/MLL | | 3. UW/MLL | | 3. UW/MLL | +# +--------------------------+ +--------------------------+ +--------------------------+ +# | 2. UW/CSMA_ALOHA | | 2. UW/CSMA_ALOHA | | 2. UW/CSMA_ALOHA | +# +--------------------------+ +--------------------------+ +--------------------------+ +# | 1. Module/MPhy/BPSK | | 1. Module/MPhy/BPSK | | 1. Module/MPhy/BPSK | +# +--------------------------+ +--------------------------+ +--------------------------+ +# | | | | | | +# +----------------------------------------------------------------------------------------+ +# | UnderwaterChannel | +# +----------------------------------------------------------------------------------------+ +###################################### +# Flags to enable or disable options # +###################################### +set opt(trace_files) 0 +set opt(bash_parameters) 0 + +##################### +# 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 libuwinterference.so +load libUwmStd.so +load libUwmStdPhyBpskTracer.so +load libuwphy_clmsgs.so +load libuwstats_utilities.so +load libuwphysical.so +load libuwposbasedrt.so +#load libuwnoderep.so; #non riesco ad importarla +#load libuwsecurity_clmsg.so; #non riesco ad importarla +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) 2 ;# Number of Nodes +set opt(starttime) 1 +set opt(stoptime) 100000 +set opt(txduration) [expr $opt(stoptime) - $opt(starttime)] +set opt(rngstream) 1 + +set opt(maxinterval_) 20.0 +set opt(freq) 25000.0 +set opt(bw) 5000.0 +#set opt(freq_hf) 60000.0 +#set opt(bw_hf) 10000.0 +set opt(bitrate) 4800.0 +#set opt(bitrate_hf) 64000.0 +set opt(ack_mode) "setNoAckMode" + + +set opt(txpower) 135.0 +#set opt(txpower_hf) 135.0 + +set opt(tdma_frame) 20 +set opt(tdma_gard) 1 + +set opt(pktsize) 125 +set opt(ctr_period) 60 + +set opt(pktsize_monitoring) 50 +set opt(auv_period) [expr $opt(tdma_frame)*2] + +#set opt(pktsize_control) 100 +#set opt(cbr_period_control) [expr $opt(cbr_period_monitoring)*4] + +set opt(pktsize_error) 1000 +set opt(auv_period_error) [expr $opt(auv_period)*5] + +set opt(op_freq) 10000000 +set opt(op_bw) 100000 +set opt(bitrate_op) 1000000 +set opt(txpower_op) 30 +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 +#set opt(ctr_period) 60 + +if {$opt(bash_parameters)} { + if {$argc != 2} { + puts "The script requires two inputs:" + puts "- the first for the Poisson CBR period" + puts "- the second for the rngstream" + puts "example: ns test_uw_rov.tcl 60 13" + 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(ctr_period) [lindex $argv 0] + set opt(rngstream) [lindex $argv 1]; + } +} + +set opt(waypoint_file) "../dbs/wp_path/rov_path.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] +set propagation [new MPropagation/Underwater] +set data_mask [new MSpectralMask/Rect] +$data_mask setFreq $opt(freq) +$data_mask setBandwidth $opt(bw) + +#set data_mask_hf [new MSpectralMask/Rect] +#$data_mask_hf setFreq $opt(freq_hf) +#$data_mask_hf setBandwidth $opt(bw_hf) + +######################### +# Module Configuration # +######################### +#UW/AUV +Module/UW/AUV set packetSize_ $opt(pktsize) +Module/UW/AUV set period_ $opt(auv_period) +Module/UW/AUV set PoissonTraffic_ 1 +Module/UW/AUV set debug_ 0 + +#UW/AUV/ERR +Module/UW/AUV/ERR set packetSize_ $opt(pktsize) +Module/UW/AUV/ERR set period_ $opt(auv_period) +Module/UW/AUV/ERR set PoissonTraffic_ 1 +Module/UW/AUV/ERR set debug_ 1 + +#UW/AUV/CERR +Module/UW/AUV/CER set packetSize_ $opt(pktsize) +Module/UW/AUV/CER set period_ $opt(auv_period) +Module/UW/AUV/CER set PoissonTraffic_ 1 +Module/UW/AUV/CER set debug_ 1 + + +# BPSK +Module/MPhy/BPSK set BitRate_ $opt(bitrate) +Module/MPhy/BPSK set TxPower_ $opt(txpower) + +#FLOODING +Module/UW/FLOODING set ttl_ 2 +Module/UW/FLOODING set maximum_cache_time__time_ $opt(stoptime) + + +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 + +Module/UW/TDMA set frame_duration $opt(tdma_frame) +Module/UW/TDMA set fair_mode 1 +Module/UW/TDMA set guard_time $opt(tdma_gard) +Module/UW/TDMA set tot_slots $opt(n_auv) + +# 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 "suv.tcl" + +for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { + createAUV $id1 +} +createSUV $opt(n_auv) +#createROV [expr $opt(n_auv) + 1] + +################################ +# Inter-node_leader module connection # +################################ + +proc connectNodes {id1} { + global ipif_suv ipr_suv portnum_suv portnum_auv portnum2_suv portnum2_auv + global suv_app suv_err + global ipif_auv auv_app auv_err + $suv_app($id1) set destAddr_ [$ipif_auv($id1) addr] + $suv_app($id1) set destPort_ $portnum_auv($id1) + + $suv_err($id1) set destAddr_ [$ipif_auv($id1) addr] + $suv_err($id1) set destPort_ $portnum2_auv($id1) + + + $auv_app($id1) set destAddr_ [$ipif_suv addr] + $auv_app($id1) set destPort_ $portnum_suv($id1) + + $auv_err($id1) set destAddr_ [$ipif_suv addr] + $auv_err($id1) set destPort_ $portnum2_suv($id1) +} + +# Setup flows + +for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { + #for {set id2 0} {$id2 < $opt(n_auv)} {incr id2} { + # if {$id1 != $id2} { + connectNodes $id1 + # } + #} +} + +# Fill ARP tables +for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { + #for {set id2 0} {$id2 < $opt(n_auv)} {incr id2} { + # $mll_auv($id1) addentry [$ipif_auv($id2) addr] [$mac_auv($id2) addr] + # $mll_op_auv($id1) addentry [$ipif_auv($id2) addr] [$mac_op_auv($id2) addr] + #} + $mll_auv($id1) addentry [$ipif_suv addr] [$mac_suv addr] + # $mll_diver($id1) addentry [$ipif_rov addr] [$mac_rov addr] + $mll_op_auv($id1) addentry [$ipif_suv addr] [$mac_op_suv addr] + # $mll_hf_diver($id1) addentry [$ipif_rov addr] [$mac_rov addr] + $mll_suv addentry [$ipif_auv($id1) addr] [$mac_auv($id1) addr] + $mll_op_suv addentry [$ipif_auv($id1) addr] [$mac_op_auv($id1) addr] +} + +#$mll_suv addentry [$ipif_rov addr] [$mac_rov addr] +#$mll_op_suv addentry [$ipif_rov addr] [$mac_op_rov addr] + +#$mll_rov addentry [$ipif_leader addr] [$mac_leader addr] +#$mll_op_rov addentry [$ipif_leader addr] [$mac_op_leader addr] +Position/UWSM debug_ 0 +# Setup positions +set position_suv [new "Position/UWSM"] +$position_suv setX_ 0 +$position_suv setY_ 0 +$position_suv setZ_ -1 + +#$position_rov setX_ 0 +#$position_rov setY_ 10 +#$position_rov setZ_ -1000 + +for {set id 0} {$id < $opt(n_auv)} {incr id} { + + #$cbr_suv($id) setPosition $position_suv + $suv_app($id) setPosition $position_suv + $suv_err($id) setPosition $position_suv + + Position/UWSM debug_ 0 + + set position_auv($id) [new "Position/UWSM"] + $position_auv($id) setX_ [expr -50 * (1 + $id % $opt(n_auv)/2) - 25 + 50 * rand()] + $position_auv($id) setY_ [expr -50 + 100 * ($id%2) - 25 + 50 * rand()] + $position_auv($id) setZ_ -1000 + + $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_suv addr] [$ipif_suv addr] + $ipr_suv addRoute [$ipif_auv($id) addr] [$ipif_auv($id) addr] + + # $ipr2_diver($id) addRoute [$ipif2_rov addr] [$ipif2_leader addr] + # $ipr2_leader addRoute [$ipif2_diver($id) addr] [$ipif2_diver($id) addr] +} +#$ipr_leader addRoute [$ipif_rov addr] [$ipif_rov 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" + for {set id 0} {$id < $opt(n_auv)} {incr id} { + $ns at $t "$suv_app($id) sendPosition [expr $x+$id] [expr $y+$id] [expr $z+$id]" + } + } +} + + + + +#$ns at $opt(starttime) "$cbr3_suv($opt(n_auv)) start" +#$ns at $opt(stoptime) "$cbr3_suv($opt(n_auv)) stop" + +for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { + #$ns at $opt(starttime) "$cbr_suv($id1) start" + #$ns at $opt(stoptime) "$cbr_suv($id1) stop" + + $ns at $opt(starttime) "$suv_app($id1) start" + $ns at $opt(stoptime) "$suv_app($id1) stop" + + $ns at $opt(starttime) "$auv_app($id1) start" + $ns at $opt(stoptime) "$auv_app($id1) stop" + + $ns at $opt(starttime) "$auv_err($id1) start" + $ns at $opt(stoptime) "$auv_err($id1) stop" + + $ns at $opt(starttime) "$suv_err($id1) start" + $ns at $opt(stoptime) "$suv_err($id1) stop" + + #$ns at $opt(starttime) "$cbr3_auv($id1) start" + #$ns at $opt(stoptime) "$cbr3_auv($id1) stop" + + #$ns at $opt(starttime) "$mac_auv($id1) start" + #$ns at $opt(stoptime) "$mac_auv($id1) stop" + + #$ns at $opt(starttime) "$mac_op_auv($id1) start" + #$ns at $opt(stoptime) "$mac_op_auv($id1) stop" + + +} + +#$ns at $opt(starttime) "$mac_suv start" +#$ns at $opt(stoptime) "$mac_suv stop" + +#$ns at $opt(starttime) "$mac_op_suv start" +#$ns at $opt(stoptime) "$mac_op_suv stop" + +proc update_and_check {} { + set outfile [open "test_uwauv_results.csv" "a"] + global position_auv position_suv auv_app suv_app opt n_auv auv_err suv_err + for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { + $position_auv($id1) update + $position_suv update + puts $outfile "positions AUV: x( $id1 ) = [$auv_app($id1) getX], y = [$auv_app($id1) getY], z = [$auv_app($id1) getZ]" + puts $outfile "positions AUV_ERR: x( $id1 ) = [$auv_err($id1) getX], y = [$auv_err($id1) getY], z = [$auv_err($id1) getZ]" + } + puts $outfile "positions SUV: x = [$suv_app(0) getX], y = [$suv_app(0) getY], z = [$suv_app(0) getZ]" + puts $outfile "positions SUV_ERR: x = [$suv_err(0) getX], y = [$suv_err(0) getY], z = [$suv_err(0) getZ]" + #puts "positions AUV: x = [$applicationAUV getX], y = [$applicationAUV getY], z = [$applicationAUV getZ]" + + close $outfile +} +### + +################### +# 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_suv_coordinates + global ipr_suv ipif_suv udp_suv phy + global suv_app suv_err + global auv_app auv_err mac_auv + global node_suv_stats tmp_node_suv_stats ipif_auv ipif_suv + + puts "---------------------------------------------------------------------" + puts "Simulation summary" + puts "Leader addr = [$ipif_suv addr]" + for {set i 0} {$i < $opt(n_auv)} {incr i} { + puts "Diver addr = [$ipif_auv($i) addr]" + #puts "Packets in buffer [$mac_auv($i) get_buffer_size]" + } + puts "number of divers : $opt(n_auv)" + puts "simulation length: $opt(txduration) s" + puts "---------------------------------------------------------------------" + + set sum_cbr_throughput 0 + set sum_cbr_sent_pkts 0.0 + set sum_cbr_rcv_pkts 0.0 + + set sum_cbr_throughput2 0 + set sum_cbr_sent_pkts2 0.0 + set sum_cbr_rcv_pkts2 0.0 + + set sum_cbr_throughput3 0 + set sum_cbr_sent_pkts3 0.0 + set sum_cbr_rcv_pkts3 0.0 + + set sum_cbr_throughput4 0 + set sum_cbr_sent_pkts4 0.0 + set sum_cbr_rcv_pkts4 0.0 + + + for {set i 0} {$i < $opt(n_auv)} {incr i} { + set cbr_throughput [$suv_app($i) getthr] + set cbr_sent_pkts [$auv_app($i) getsentpkts] + set cbr_rcv_pkts [$suv_app($i) getrecvpkts] + + set cbr_throughput2 [$auv_app($i) getthr] + set cbr_sent_pkts2 [$suv_app($i) getsentpkts] + set cbr_rcv_pkts2 [$auv_app($i) getrecvpkts] + + set cbr_throughput4 [$suv_err($i) getthr] + set cbr_sent_pkts4 [$auv_err($i) getsentpkts] + set cbr_rcv_pkts4 [$suv_err($i) getrecvpkts] + + #set cbr_throughput3 [$cbr3_suv($i) getthr] + #set cbr_sent_pkts3 [$cbr3_auv($i) getsentpkts] + #set cbr_rcv_pkts3 [$cbr3_suv($i) getrecvpkts] + + set sum_cbr_throughput [expr $sum_cbr_throughput + $cbr_throughput] + set sum_cbr_sent_pkts [expr $sum_cbr_sent_pkts + $cbr_sent_pkts] + set sum_cbr_rcv_pkts [expr $sum_cbr_rcv_pkts + $cbr_rcv_pkts] + + set sum_cbr_throughput2 [expr $sum_cbr_throughput2 + $cbr_throughput2] + set sum_cbr_sent_pkts2 [expr $sum_cbr_sent_pkts2 + $cbr_sent_pkts2] + set sum_cbr_rcv_pkts2 [expr $sum_cbr_rcv_pkts2 + $cbr_rcv_pkts2] + + set sum_cbr_throughput4 [expr $sum_cbr_throughput4 + $cbr_throughput4] + set sum_cbr_sent_pkts4 [expr $sum_cbr_sent_pkts4 + $cbr_sent_pkts4] + set sum_cbr_rcv_pkts4 [expr $sum_cbr_rcv_pkts4 + $cbr_rcv_pkts4] + } + + #set sum_cbr_sent_pkts [expr $sum_cbr_sent_pkts + [$cbr_suv($opt(n_auv)) getsentpkts]] + #set sum_cbr_sent_pkts3 [expr $sum_cbr_sent_pkts3 + [$cbr3_suv getsentpkts]] + + #set sum_cbr_rcv_pkts [expr $sum_cbr_rcv_pkts + [$cbr_suv($opt(n_auv)) getrecvpkts]] + #set sum_cbr_rcv_pkts3 [expr $sum_cbr_rcv_pkts3 + [$cbr3_suv($opt(n_auv)) getrecvpkts]] + + #set sum_cbr_throughput [expr $sum_cbr_throughput + [$cbr_suv($opt(n_auv)) getthr]] + #set sum_cbr_throughput3 [expr $sum_cbr_throughput3 + [$cbr3_suv($opt(n_auv)) getthr]] + + #set sum_cbr_throughput2 [expr [$cbr2_suv(0) getthr] + $sum_cbr_throughput2] + #set sum_cbr_rcv_pkts2 [expr [$cbr2_suv(0) getrecvpkts] + $sum_cbr_rcv_pkts2] + #set sum_cbr_sent_pkts2 [expr $sum_cbr_sent_pkts2 + [$cbr2_suv($opt(n_auv)) getsentpkts]] + + set ipheadersize [$ipif_suv getipheadersize] + set udpheadersize [$udp_suv getudpheadersize] + set cbrheadersize [$suv_app(0) getcbrheadersize] + + + puts "IP Pkt Header Size : $ipheadersize" + puts "UDP Header Size : $udpheadersize" + puts "CBR Header Size : $cbrheadersize" + + puts "Traffic MONITORING ---------------------------------------------" + puts "Mean Throughput : [expr ($sum_cbr_throughput/(1+$opt(n_auv)))]" + puts "Sent Packets : $sum_cbr_sent_pkts" + puts "Received Packets : $sum_cbr_rcv_pkts" + puts "Packet Delivery Ratio : [expr $sum_cbr_rcv_pkts / $sum_cbr_sent_pkts * 100]" + + puts "Traffic CONTROL ---------------------------------------------" + puts "Mean Throughput : [expr ($sum_cbr_throughput2/($opt(n_auv)))]" + puts "Sent Packets : $sum_cbr_sent_pkts2" + puts "Received Packets : $sum_cbr_rcv_pkts2" + puts "Packet Delivery Ratio : [expr $sum_cbr_rcv_pkts2 / $sum_cbr_sent_pkts2 * 100]" + + puts "Traffic ERROR ---------------------------------------------" + puts "Mean Throughput : [expr ($sum_cbr_throughput4/($opt(n_auv)))]" + puts "Sent Packets : $sum_cbr_sent_pkts4" + puts "Received Packets : $sum_cbr_rcv_pkts4" + puts "Packet Delivery Ratio : [expr $sum_cbr_rcv_pkts4 / $sum_cbr_sent_pkts4 * 100]" + + + #puts "Traffic 3 ---------------------------------------------" + #puts "Mean Throughput : [expr ($sum_cbr_throughput3/(1+$opt(n_diver)))]" + #puts "Sent Packets : $sum_cbr_sent_pkts3" + #puts "Received Packets : $sum_cbr_rcv_pkts3" + #puts "Packet Delivery Ratio : [expr $sum_cbr_rcv_pkts3 / $sum_cbr_sent_pkts3 * 100]" + + $ns flush-trace + close $opt(tracefile) +} + +################### +# start simulation +################### +$ns at [expr $opt(stoptime) + 250.0] "finish; $ns halt" +$ns run From c4ab409ea1454916467fe025555afc8091375a54 Mon Sep 17 00:00:00 2001 From: alessiaortile Date: Mon, 29 May 2023 19:45:25 +0200 Subject: [PATCH 03/36] add error tx period + plot trajectories --- DESERT_Addons/uwauv/uwauvctrer-module.cc | 2 +- DESERT_Addons/uwauv/uwauverror-module.cc | 28 +++++++++--- DESERT_Addons/uwauv/uwauverror-module.h | 29 ++++++++++++- .../desert_samples/AUV/plot_coordinates.py | 43 +++++++++++++++++++ .../AUV/test_uwmulti_traffic_auv.tcl | 34 +++++++++------ 5 files changed, 115 insertions(+), 21 deletions(-) create mode 100644 DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_coordinates.py diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.cc b/DESERT_Addons/uwauv/uwauvctrer-module.cc index 76e92c3b..79871908 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.cc +++ b/DESERT_Addons/uwauv/uwauvctrer-module.cc @@ -217,7 +217,7 @@ void UwAUVCtrErModule::recv(Packet* p) { } } else { //packet in order - posit->setdest(uwAUVh->x(),uwAUVh->y(),uwAUVh->z(),uwAUVh->speed()); + posit->setdest(uwAUVh->x(),uwAUVh->y(),posit->getZ(),uwAUVh->speed()); last_sn_confirmed = uwAUVh->sn(); } diff --git a/DESERT_Addons/uwauv/uwauverror-module.cc b/DESERT_Addons/uwauv/uwauverror-module.cc index 80c5abd1..0b05bade 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.cc +++ b/DESERT_Addons/uwauv/uwauverror-module.cc @@ -75,6 +75,7 @@ static class UwAUVErrorModuleClass : public TclClass { } class_module_uwAUV; + UwAUVErrorModule::UwAUVErrorModule() : UwCbrModule() , last_sn_confirmed(0) @@ -85,6 +86,7 @@ UwAUVErrorModule::UwAUVErrorModule() , drop_old_waypoints(0) , log_flag(0) , out_file_stats(0) + , period(60) { UWSMPosition p = UWSMPosition(); speed = 5; @@ -92,6 +94,7 @@ UwAUVErrorModule::UwAUVErrorModule() bind("ackTimeout_", (int*) &ackTimeout); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); bind("log_flag_", (int*) &log_flag ); + bind("period_", (int*) &period ); if (ackTimeout < 0) { cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" << std::endl; @@ -110,12 +113,14 @@ UwAUVErrorModule::UwAUVErrorModule(UWSMPosition* p) , drop_old_waypoints(0) , log_flag(0) , out_file_stats(0) + , period(60) { posit = p; speed = 5; bind("ackTimeout_", (int*) &ackTimeout); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); bind("log_flag_", (int*) &log_flag ); + bind("period_", (int*) &period ); if (ackTimeout < 0) { cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" << std::endl; @@ -203,6 +208,18 @@ int UwAUVErrorModule::command(int argc, const char*const* argv) { 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_uwAUV_ctr* uwAUVh = HDR_UWAUV_CTR(p); @@ -217,13 +234,10 @@ void UwAUVErrorModule::initPkt(Packet* p) { double randomValue = distrib(generator) ; - std::cout << NOW << " UwAUVErrorModule::r.v " - << randomValue<< std::endl; - - if(randomValue < 0.75){ + if(randomValue > 0.75){ uwAUVh->x() = posit->getX(); uwAUVh->y() = posit->getY(); - uwAUVh->z() = posit->getZ(); + //uwAUVh->z() = posit->getZ(); uwAUVh->speed() = speed; uwAUVh->sn() = ++sn; this->p = p; @@ -237,7 +251,7 @@ void UwAUVErrorModule::initPkt(Packet* p) { hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); uwAUVh->x() = posit->getX(); uwAUVh->y() = posit->getY(); - uwAUVh->z() = posit->getZ(); + //uwAUVh->z() = posit->getZ(); uwAUVh->speed() = speed; uwAUVh->sn() = sn; if (debug_) { @@ -272,7 +286,7 @@ void UwAUVErrorModule::recv(Packet* p) { hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); if(uwAUVh->ack() == sn + 1) { - sendTmr_.force_cancel(); + //sendTmr_.force_cancel(); this->p = NULL; } diff --git a/DESERT_Addons/uwauv/uwauverror-module.h b/DESERT_Addons/uwauv/uwauverror-module.h index 54c238b3..359de669 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.h +++ b/DESERT_Addons/uwauv/uwauverror-module.h @@ -59,6 +59,20 @@ using namespace std; class UwAUVErrorModule; +/** +* 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(UwAUVErrorModule *m) : UwSendTimer((UwCbrModule*)(m)){ + }; +}; + /** * UwAUVModule class is used to manage UWAUV packets and to collect statistics about them. */ @@ -114,6 +128,19 @@ class UwAUVErrorModule : public UwCbrModule { */ virtual void recv(Packet* p, Handler* h); + /** + * 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 * @@ -175,7 +202,7 @@ class UwAUVErrorModule : public UwCbrModule { int log_flag; /**< Flag to enable log file writing.*/ Packet* p; - + int period; std::ofstream out_file_stats; /**< Output stream for the textual file of debug */ }; 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..deff4265 --- /dev/null +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_coordinates.py @@ -0,0 +1,43 @@ +import csv +import matplotlib.pyplot as plt + +def plot_coordinates(file_path,x,y,z): + + with open(file_path, 'r') as file: + reader = csv.reader(file) + for row in reader: + x.append(float(row[0])) + y.append(float(row[1])) + z.append(float(row[2])) + + + + +# Example usage +X_0 = [] +Y_0 = [] +Z_0 = [] +X_1 = [] +Y_1 = [] +Z_1 = [] +X_s = [] +Y_s = [] +Z_s = [] +file_path = 'test_uwauv0_results.csv' # Replace with your file pathplot_coordinates(file_path) +plot_coordinates(file_path,X_0,Y_0,Z_0) +file_path = 'test_uwauv1_results.csv' # Replace with your file pathplot_coordinates(file_path) +plot_coordinates(file_path,X_1,Y_1,Z_1) +file_path = 'test_uwsuv_results.csv' # Replace with your file pathplot_coordinates(file_path) +plot_coordinates(file_path,X_s,Y_s,Z_s) + +fig = plt.figure() +ax = fig.add_subplot(111, projection='3d') +ax.plot(X_0, Y_0, Z_0, label='auv_0') +ax.plot(X_1, Y_1, Z_1, label='auv_1') +ax.plot(X_s, Y_s, Z_s,label='sv') +ax.set_xlabel('X') +ax.set_ylabel('Y') +ax.set_zlabel('Z') +ax.legend() +#ax.set_zlabel('Z') +plt.show() \ No newline at end of file diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl index 4e344418..a2da1e8c 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl @@ -430,7 +430,7 @@ foreach line $data { if {[regexp {^(.*),(.*),(.*),(.*)$} $line -> t x y z]} { $ns at $t "update_and_check" for {set id 0} {$id < $opt(n_auv)} {incr id} { - $ns at $t "$suv_app($id) sendPosition [expr $x+$id] [expr $y+$id] [expr $z+$id]" + $ns at $t "$suv_app($id) sendPosition [expr $x+($id*10)] [expr $y-($id*10)] [expr $z+$id]" } } } @@ -476,19 +476,29 @@ for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { #$ns at $opt(stoptime) "$mac_op_suv stop" proc update_and_check {} { - set outfile [open "test_uwauv_results.csv" "a"] + set outfile_auv0 [open "test_uwauv0_results.csv" "a"] + set outfile_auv1 [open "test_uwauv1_results.csv" "a"] + set outfile_suv [open "test_uwsuv_results.csv" "a"] global position_auv position_suv auv_app suv_app opt n_auv auv_err suv_err - for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { - $position_auv($id1) update - $position_suv update - puts $outfile "positions AUV: x( $id1 ) = [$auv_app($id1) getX], y = [$auv_app($id1) getY], z = [$auv_app($id1) getZ]" - puts $outfile "positions AUV_ERR: x( $id1 ) = [$auv_err($id1) getX], y = [$auv_err($id1) getY], z = [$auv_err($id1) getZ]" - } - puts $outfile "positions SUV: x = [$suv_app(0) getX], y = [$suv_app(0) getY], z = [$suv_app(0) getZ]" - puts $outfile "positions SUV_ERR: x = [$suv_err(0) getX], y = [$suv_err(0) getY], z = [$suv_err(0) getZ]" - #puts "positions AUV: x = [$applicationAUV getX], y = [$applicationAUV getY], z = [$applicationAUV getZ]" + #for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { + # $position_auv($id1) update + # $position_suv update + # puts $outfile "positions AUV: x( $id1 ) = [$auv_app($id1) getX], y = [$auv_app($id1) getY], z = [$auv_app($id1) getZ]" + # puts $outfile "positions AUV_ERR: x( $id1 ) = [$auv_err($id1) getX], y = [$auv_err($id1) getY], z = [$auv_err($id1) getZ]" + #} + + $position_auv(0) update + $position_auv(1) update + $position_suv update + + puts $outfile_auv0 "[$auv_app(0) getX],[$auv_app(0) getY],[$auv_app(0) getZ]" + puts $outfile_auv1 "[$auv_app(1) getX],[$auv_app(1) getY],[$auv_app(1) getZ]" + puts $outfile_suv "[$suv_app(0) getX],[$suv_app(0) getY],[$suv_app(0) getZ]" + #puts "positions AUV: x = [$applicationAUV getX], y = [$applicationAUV getY], z = [$applicationAUV getZ]" - close $outfile + close $outfile_auv0 + close $outfile_auv1 + close $outfile_suv } ### From 6e3dd908b4764753af6ae68d14a3bc07aece72eb Mon Sep 17 00:00:00 2001 From: alessiaortile Date: Fri, 2 Jun 2023 14:47:04 +0200 Subject: [PATCH 04/36] log-error sending-error reception correction --- DESERT_Addons/uwauv/uwauv-init.tcl | 6 +- DESERT_Addons/uwauv/uwauvctrer-module.cc | 162 ++++++++++++++---- DESERT_Addons/uwauv/uwauvctrer-module.h | 46 ++++- DESERT_Addons/uwauv/uwauverror-module.cc | 102 ++++++++--- DESERT_Addons/uwauv/uwauverror-module.h | 6 +- .../AUV/test_uwmulti_traffic_auv.tcl | 26 +-- 6 files changed, 271 insertions(+), 77 deletions(-) diff --git a/DESERT_Addons/uwauv/uwauv-init.tcl b/DESERT_Addons/uwauv/uwauv-init.tcl index c1c14d8c..f32cdfd4 100644 --- a/DESERT_Addons/uwauv/uwauv-init.tcl +++ b/DESERT_Addons/uwauv/uwauv-init.tcl @@ -41,7 +41,7 @@ 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_ 0 +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 @@ -72,7 +72,7 @@ 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_ 0 +Module/UW/AUV/ERR set drop_out_of_order_ 1 Module/UW/AUV/ERR set adaptiveRTO_ 0 Module/UW/AUV/ERR instproc init {args} { @@ -86,7 +86,7 @@ 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_ 1 -Module/UW/AUV/CER set drop_out_of_order_ 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} { diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.cc b/DESERT_Addons/uwauv/uwauvctrer-module.cc index 79871908..36624346 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.cc +++ b/DESERT_Addons/uwauv/uwauvctrer-module.cc @@ -74,16 +74,20 @@ UwAUVCtrErModule::UwAUVCtrErModule(UWSMPosition* p) : UwCbrModule() , ack(0) , last_sn_confirmed(0) + , sn(0) , ackTimeout(10) , drop_old_waypoints(1) , log_flag(0) - , out_file_stats(0) + , pos_log(0) + , alarm_mode(false) + , period(60) { posit=p; speed=5; bind("ackTimeout_", (int*) &ackTimeout); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); bind("log_flag_", (int*) &log_flag ); + bind("period_", (int*) &period ); if (ackTimeout < 0) { cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" << std::endl; @@ -95,10 +99,13 @@ UwAUVCtrErModule::UwAUVCtrErModule() : UwCbrModule() , ack(0) , last_sn_confirmed(0) + , sn(0) , ackTimeout(10) , drop_old_waypoints(1) , log_flag(0) - , out_file_stats(0) + //, out_file_stats(0) + , alarm_mode(false) + , period(60) { p = NULL; @@ -109,6 +116,7 @@ UwAUVCtrErModule::UwAUVCtrErModule() bind("ackTimeout_", (int*) &ackTimeout); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); bind("log_flag_", (int*) &log_flag ); + bind("period_", (int*) &period ); if (ackTimeout < 0) { cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" << std::endl; @@ -157,7 +165,7 @@ int UwAUVCtrErModule::command(int argc, const char*const* argv) { return TCL_OK; } } - else if(argc == 5){ + /*else if(argc == 4){ /**if (strcasecmp(argv[1], "sendPosition") == 0) { newX = atof(argv[2]); newY = atof(argv[3]); @@ -177,8 +185,9 @@ int UwAUVCtrErModule::command(int argc, const char*const* argv) { this->transmit(); tcl.resultf("%s", "position Setted"); return TCL_OK; - }**/ - } + } + }*/ + return UwCbrModule::command(argc,argv); } @@ -186,20 +195,78 @@ void UwAUVCtrErModule::start() {} void UwAUVCtrErModule::setPosition(UWSMPosition* p){ posit = p; + +} + +void UwAUVCtrErModule::transmit() { + sendPkt(); + + if (debug_) { + std::cout << NOW << " UwAUVCtrErModule::Sending pkt with period: " << period + << std::endl; + } + + + sendTmr_.resched(period); } void UwAUVCtrErModule::initPkt(Packet* p) { hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); + hdr_uwcbr *uwcbrh = HDR_UWCBR(p); + uwAUVh->ack() = ack; - ack = 0; + if(this->p == NULL){ + + if ((abs(posit->getX() - x_auv) < 0.1) && (abs(posit->getY() - y_auv ) < 0.1)){ + + uwAUVh->speed() = 100; + alarm_mode = false; + uwAUVh->sn() = ++sn; + this->p = p; + + if (debug_) { + std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) ERROR SOLVED" + << std::endl; + } + + } + + if (debug_) { + std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) ACK recv" + << std::endl; + } + + //Retransmission + }else if ((abs(posit->getX() - x_auv) < 0.1) && (abs(posit->getY() - y_auv ) < 0.1) ){ + + uwAUVh->speed() = 100; + alarm_mode = false; + uwAUVh->sn() = sn; + + if (debug_) { + std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) Retransmission ERROR SOLVED" + << std::endl; + } + } + UwCbrModule::initPkt(p); + if (debug_) { std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) setting last ack" << std::endl; } + + if (log_flag == 1) { + + pos_log.open("position_log.csv",std::ios_base::app); + pos_log << NOW << "," << posit->getX() << ","<< posit->getY() + << ","<< posit->getZ() << std::endl; + pos_log.close(); + + } } void UwAUVCtrErModule::recv(Packet* p, Handler* h) { @@ -209,41 +276,74 @@ void UwAUVCtrErModule::recv(Packet* p, Handler* h) { void UwAUVCtrErModule::recv(Packet* p) { hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); + + + if(uwAUVh->ack() == sn + 1) { //ack received + //sendTmr_.force_cancel(); + this->p = NULL; + } + + + if(uwAUVh->ack() > 0 && debug_) + std::cout << NOW << " UwAUVErrorModule::recv(Packet *p) error ACK " + << "received " << uwAUVh->ack()<< std::endl; + else if((uwAUVh->ack())<0 && debug_) + std::cout << NOW << " UwAUVErrorModule::recv(Packet *p) error NACK " + <<"received"<< std::endl; + + if (!alarm_mode){ + + if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { //obsolete packets + if (debug_) { + std::cout << NOW << " UwAUVCtrErrModule::old error with sn " + << uwAUVh->sn() << " dropped " << std::endl; + } + + } else { //packet in order + x_auv = uwAUVh->x(); + y_auv = uwAUVh->y(); + posit->setdest(x_auv,y_auv,posit->getZ(),1); + last_sn_confirmed = uwAUVh->sn(); + alarm_mode = true; + + if (log_flag == 1) { + err_log.open("error_log.csv",std::ios_base::app); + err_log << NOW << "," << x_auv<<","<sn() <= last_sn_confirmed) { //obsolete packets - if (debug_) { - std::cout << NOW << " UwAUVCtrErrModule::old error with sn " - << uwAUVh->sn() << " dropped " << std::endl; } - } else { //packet in order - posit->setdest(uwAUVh->x(),uwAUVh->y(),posit->getZ(),uwAUVh->speed()); - last_sn_confirmed = uwAUVh->sn(); - } + ack = last_sn_confirmed+1; - ack = last_sn_confirmed+1; + if (log_flag == 1) { + pos_log.open("position_log.csv",std::ios_base::app); + pos_log<< NOW << ","<getX() << ","<< posit->getY() + << ","<< posit->getZ() << std::endl; + pos_log.close(); + } - if (log_flag == 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 << " UwAUVCtrErrModule::recv(Packet *p) SV received new " + "error: X = " << uwAUVh->x() << ", Y = " << uwAUVh->y() + << ", Z = " << uwAUVh->z() << " speed "<< uwAUVh->speed()<< std::endl; + } - if (debug_) { - std::cout << NOW << " UwAUVCtrErrModule::recv(Packet *p) SUV received new " - "error: X = " << uwAUVh->x() << ", Y = " << uwAUVh->y() - << ", Z = " << uwAUVh->z()<< std::endl; - } - UwCbrModule::recv(p); + UwCbrModule::recv(p); + if (debug_) + cout << NOW << " ACK sent immediately with standard priority " + << std::endl; + } + UwCbrModule::sendPkt(); - if (debug_) - cout << NOW << " ACK sent immediately with standard priority " - << std::endl; + + if (debug_) + std::cout << NOW << " UwAUVCtrErrModule::recv(Packet *p) Packet dropped: " + << "alarm mode "<< std::endl; + } diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.h b/DESERT_Addons/uwauv/uwauvctrer-module.h index 410ea1af..e60bd3bf 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.h +++ b/DESERT_Addons/uwauv/uwauvctrer-module.h @@ -50,6 +50,7 @@ #include "uwsmposition.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. */ @@ -57,7 +58,21 @@ #define HDR_UWAUV_CTR(p) (hdr_uwAUV_ctr::access(p)) #define HDR_UWAUV_ERROR(p) (hdr_uwAUV_error::access(p)) using namespace std; -class UwAUVCtrModule; +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)){ + }; +}; /** @@ -116,6 +131,19 @@ class UwAUVCtrErModule : public UwCbrModule { * @return the current AUVCtr position */ inline UWSMPosition* getPosition() { return posit;} + + /** + * Reset retransmissions + */ + inline void reset_retx() {p=NULL; sendTmr_.force_cancel();} + + + /** + * Creates and transmits a packet. + * + * @see UwCbrModule::sendPkt() + */ + virtual void transmit(); /** @@ -164,18 +192,22 @@ class UwAUVCtrErModule : public UwCbrModule { protected: UWSMPosition* posit; /**< Controller position.*/ - int last_sn_confirmed; + int last_sn_confirmed; /**< Sequence number of the last command Packete received.*/ + int sn; /**Sequence number of the last control packet sent.*/ int ack; int drop_old_waypoints; - 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 x_auv; /**< X of the last AUV position with an error.*/ + float y_auv; /**< Y of the last AUV position with an error.*/ + float z_auv; /**< Z of the last AUV position with an error.*/ float speed; /**< Moving speed sent to the AUV.*/ - int sn; /**Sequence number of the last control packet sent.*/ + int period; + Packet* p; int log_flag; - std::ofstream out_file_stats; + std::ofstream pos_log; + std::ofstream err_log; int ackTimeout; + bool alarm_mode; }; diff --git a/DESERT_Addons/uwauv/uwauverror-module.cc b/DESERT_Addons/uwauv/uwauverror-module.cc index 0b05bade..77b59529 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.cc +++ b/DESERT_Addons/uwauv/uwauverror-module.cc @@ -80,10 +80,11 @@ UwAUVErrorModule::UwAUVErrorModule() : UwCbrModule() , last_sn_confirmed(0) , sn(0) + , ack(0) , ackPolicy(ACK_PIGGYBACK) , ackTimeout(10) , ackNotPgbk(0) - , drop_old_waypoints(0) + , drop_old_waypoints(1) , log_flag(0) , out_file_stats(0) , period(60) @@ -101,16 +102,18 @@ UwAUVErrorModule::UwAUVErrorModule() ackTimeout = 10; } + } UwAUVErrorModule::UwAUVErrorModule(UWSMPosition* p) : UwCbrModule() , last_sn_confirmed(0) , sn(0) + , ack(0) , ackPolicy(ACK_PIGGYBACK) , ackTimeout(10) , ackNotPgbk(0) - , drop_old_waypoints(0) + , drop_old_waypoints(1) , log_flag(0) , out_file_stats(0) , period(60) @@ -126,6 +129,7 @@ UwAUVErrorModule::UwAUVErrorModule(UWSMPosition* p) << std::endl; ackTimeout = 10; } + } @@ -212,7 +216,7 @@ void UwAUVErrorModule::transmit() { sendPkt(); if (debug_) { - std::cout << NOW << " UwAUVErrorModule::Sending pkt with period: " << period_ + std::cout << NOW << " UwAUVErrorModule::Sending pkt with period: " << period << std::endl; } @@ -221,39 +225,57 @@ void UwAUVErrorModule::transmit() { } void UwAUVErrorModule::initPkt(Packet* p) { - - //hdr_uwAUV_ctr* uwAUVh = HDR_UWAUV_CTR(p); + hdr_uwcbr *uwcbrh = HDR_UWCBR(p); + hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); + + uwAUVh->ack() = ack; + ack = 0; if(this->p == NULL){ + random_device rd; mt19937 generator(rd()); uniform_real_distribution distrib(0.0, 1.0); - hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); + double randomValue = distrib(generator) ; - if(randomValue > 0.75){ + if(randomValue > 0.65){ + uwAUVh->x() = posit->getX(); uwAUVh->y() = posit->getY(); - //uwAUVh->z() = posit->getZ(); - uwAUVh->speed() = speed; + x_e = posit->getX(); + y_e = posit->getY(); + uwAUVh->sn() = ++sn; this->p = p; + + //TODO: stop devices when send the alarm + + if (debug_) { std::cout << NOW << " UwAUVErroModule::initPkt(Packet *p) " - << "ERROR!"<< std::endl; + << "ERROR!"<<"(speed="<getSpeed()<<")" << std::endl; } + + if (log_flag == 1) { + error_log.open("error_calling_log.csv",std::ios_base::app); + error_log << NOW << "," << posit->getX()<<","<getY()<< std::endl; + error_log.close(); + } + } } - else{ - hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); - uwAUVh->x() = posit->getX(); - uwAUVh->y() = posit->getY(); - //uwAUVh->z() = posit->getZ(); - uwAUVh->speed() = speed; + else{ //Retransmit + + + //retrasmission of the point where the error was called + uwAUVh->x() = x_e; + uwAUVh->y() = y_e; uwAUVh->sn() = sn; + if (debug_) { std::cout << NOW << " UwAUVErroModule::initPkt(Packet *p) " << "Retransmitting"<< std::endl; @@ -265,16 +287,18 @@ void UwAUVErrorModule::initPkt(Packet* p) { std::cout << NOW << " UwAUVErrorModule::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 << " UwAUVErrorModule::sending packet with priority " - << (int)uwcbrh->priority() << std::endl; + if (log_flag == 1) { + out_file_stats.open("postion_log_a.csv",std::ios_base::app); + out_file_stats << left << NOW << "," << posit->getX() << ","<< posit->getY() + << "," << posit->getZ() << std::endl; + out_file_stats.close(); } - //priority_ = 0; + } void UwAUVErrorModule::recv(Packet* p, Handler* h) { @@ -286,9 +310,41 @@ void UwAUVErrorModule::recv(Packet* p) { hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); if(uwAUVh->ack() == sn + 1) { - //sendTmr_.force_cancel(); - this->p = NULL; + this->p = NULL; + } + + if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { //obsolete packets + if (debug_) { + std::cout << NOW << " UwAUVErrModule::old error with sn " + << uwAUVh->sn() << " dropped " << std::endl; + } + + } else { //packet in order + //TODO: When sv reaches the right position set speed > 0 + if(uwAUVh->speed() == 100){ + //posit->setdest(posit->getXdest(),posit->getYdest(),posit->getZdest(),1); + if (debug_) { + std::cout << NOW << " UwAUVErrModule::recv(Packet *p) error solved " + "AUV can move again with speed=" << posit->getSpeed()<< std::endl; + } + } + last_sn_confirmed = uwAUVh->sn(); } + + ack = last_sn_confirmed+1; + + //to update + if (log_flag == 1) { + out_file_stats.open("postion_log_a.csv",std::ios_base::app); + out_file_stats << left << NOW << "," << posit->getX() << ","<< posit->getY() + << "," << posit->getZ() << std::endl; + out_file_stats.close(); + } + + UwCbrModule::recv(p); + + + UwCbrModule::sendPkt(); if(uwAUVh->ack() > 0 && debug_) diff --git a/DESERT_Addons/uwauv/uwauverror-module.h b/DESERT_Addons/uwauv/uwauverror-module.h index 359de669..73b203e8 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.h +++ b/DESERT_Addons/uwauv/uwauverror-module.h @@ -184,7 +184,8 @@ class UwAUVErrorModule : public UwCbrModule { UWSMPosition* posit; /**< AUV position.*/ float speed; int last_sn_confirmed;/**< Sequence number of the last command Packete received.*/ - int sn; /**< If not zero, contains the ACK to the last command Packete received.*/ + int sn; + int ack; //int send_ack_immediately; /**< Flag either to send acks immediately or not.*/ std::queue buffer; /**< Packets buffer.*/ UWAUV_ACK_POLICY ackPolicy; /**< Flag to set the policy for ACK transimission, @@ -204,6 +205,9 @@ class UwAUVErrorModule : public UwCbrModule { Packet* p; int period; std::ofstream out_file_stats; /**< Output stream for the textual file of debug */ + std::ofstream error_log; + float x_e; + float y_e; }; #endif // UWAUVError_MODULE_H diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl index a2da1e8c..83bf9c2d 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl @@ -192,7 +192,7 @@ if {$opt(bash_parameters)} { } } -set opt(waypoint_file) "../dbs/wp_path/rov_path.csv" +set opt(waypoint_file) "../dbs/wp_path/rov_path_simple.csv" #random generator global defaultRNG @@ -241,7 +241,7 @@ Module/UW/AUV/ERR set debug_ 1 Module/UW/AUV/CER set packetSize_ $opt(pktsize) Module/UW/AUV/CER set period_ $opt(auv_period) Module/UW/AUV/CER set PoissonTraffic_ 1 -Module/UW/AUV/CER set debug_ 1 +Module/UW/AUV/CER set debug_ 0 # BPSK @@ -387,18 +387,20 @@ $position_suv setZ_ -1 for {set id 0} {$id < $opt(n_auv)} {incr id} { #$cbr_suv($id) setPosition $position_suv - $suv_app($id) setPosition $position_suv - $suv_err($id) setPosition $position_suv + $suv_app($id) setPosition $position_suv + $suv_err($id) setPosition $position_suv 5 Position/UWSM debug_ 0 set position_auv($id) [new "Position/UWSM"] - $position_auv($id) setX_ [expr -50 * (1 + $id % $opt(n_auv)/2) - 25 + 50 * rand()] - $position_auv($id) setY_ [expr -50 + 100 * ($id%2) - 25 + 50 * rand()] + #$position_auv($id) setX_ [expr -50 * (1 + $id % $opt(n_auv)/2) - 25 + 50 * rand()] + $position_auv($id) setX_ 0 + #$position_auv($id) setY_ [expr -50 + 100 * ($id%2) - 25 + 50 * rand()] + $position_auv($id) setY_ 0 $position_auv($id) setZ_ -1000 - $auv_app($id) setPosition $position_auv($id) - $auv_err($id) setPosition $position_auv($id) + $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_]" } @@ -430,7 +432,7 @@ foreach line $data { if {[regexp {^(.*),(.*),(.*),(.*)$} $line -> t x y z]} { $ns at $t "update_and_check" for {set id 0} {$id < $opt(n_auv)} {incr id} { - $ns at $t "$suv_app($id) sendPosition [expr $x+($id*10)] [expr $y-($id*10)] [expr $z+$id]" + $ns at $t "$suv_app($id) sendPosition [expr $x*($id*(-2))+$x] [expr $y*($id*(-2))+$y] [expr $z]" } } } @@ -491,9 +493,9 @@ proc update_and_check {} { $position_auv(1) update $position_suv update - puts $outfile_auv0 "[$auv_app(0) getX],[$auv_app(0) getY],[$auv_app(0) getZ]" - puts $outfile_auv1 "[$auv_app(1) getX],[$auv_app(1) getY],[$auv_app(1) getZ]" - puts $outfile_suv "[$suv_app(0) getX],[$suv_app(0) getY],[$suv_app(0) getZ]" + puts $outfile_auv0 "[$auv_app(0) getX],[$auv_app(0) getY],[$auv_app(0) getZ],[$auv_app(0) getSpeed]" + puts $outfile_auv1 "[$auv_app(1) getX],[$auv_app(1) getY],[$auv_app(1) getZ],[$auv_app(1) getSpeed]" + puts $outfile_suv "[$suv_app(0) getX],[$suv_app(0) getY],[$suv_app(0) getZ],[$auv_app(0) getSpeed]" #puts "positions AUV: x = [$applicationAUV getX], y = [$applicationAUV getY], z = [$applicationAUV getZ]" close $outfile_auv0 From 1a26c4750a154e98f1a8a00c42ea9fc159e696e3 Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Tue, 6 Jun 2023 22:54:32 +0200 Subject: [PATCH 05/36] branch correction --- DESERT_Addons/uwauv/autogen.sh | 33 +++++ DESERT_Addons/uwauv/m4/desert.m4 | 150 +++++++++++++++++++++ DESERT_Addons/uwauv/m4/nsallinone.m4 | 189 +++++++++++++++++++++++++++ DESERT_Addons/uwauv/m4/nsmiracle.m4 | 189 +++++++++++++++++++++++++++ 4 files changed, 561 insertions(+) create mode 100755 DESERT_Addons/uwauv/autogen.sh create mode 100644 DESERT_Addons/uwauv/m4/desert.m4 create mode 100644 DESERT_Addons/uwauv/m4/nsallinone.m4 create mode 100644 DESERT_Addons/uwauv/m4/nsmiracle.m4 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/m4/desert.m4 b/DESERT_Addons/uwauv/m4/desert.m4 new file mode 100644 index 00000000..c2e0ecd4 --- /dev/null +++ b/DESERT_Addons/uwauv/m4/desert.m4 @@ -0,0 +1,150 @@ +# +# 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 + 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 + 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 + 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 +# ]) +# +# From 067751344a497757517f3b28e86024c35ca68c21 Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Wed, 7 Jun 2023 14:33:11 +0200 Subject: [PATCH 06/36] name correction + plot update --- .../DESERT/samples/desert_samples/AUV/asv.tcl | 161 ++++++++++++++++++ .../DESERT/samples/desert_samples/AUV/auv.tcl | 9 +- .../desert_samples/AUV/plot_coordinates.py | 51 ++++-- .../DESERT/samples/desert_samples/AUV/suv.tcl | 159 ----------------- .../AUV/test_uwmulti_traffic_auv.tcl | 148 ++++++++-------- 5 files changed, 279 insertions(+), 249 deletions(-) create mode 100644 DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl delete mode 100644 DESERT_Framework/DESERT/samples/desert_samples/AUV/suv.tcl 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..a2070090 --- /dev/null +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl @@ -0,0 +1,161 @@ +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_ $opt(ctr_period) + Module/UW/AUV/CTR set PoissonTraffic_ 1 + 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/CER set packetSize_ $opt(pktsize) + Module/UW/AUV/CER set period_ $opt(ctr_period) + Module/UW/AUV/CER set PoissonTraffic_ 1 + Module/UW/AUV/CER set traffic_type_ 3 + Module/UW/AUV/CER set debug_ 0 + Module/UW/AUV/CER set log_flag_ 1 + 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] + + 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 index 64a57507..7342528f 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl @@ -5,7 +5,7 @@ proc createAUV { id } { global channel 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 --> SUV + # 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(auv_period) @@ -14,7 +14,7 @@ proc createAUV { id } { Module/UW/AUV set debug_ 0 set auv_app($id) [new Module/UW/AUV] - # TRAFFICO 2: CONTROL:SUV --> AUV + # TRAFFICO 2: CONTROL:ASV --> AUV #Module/UW/ROV/CTR set packetSize_ $opt(pktsize_control) #Module/UW/ROV/CTR set period_ $opt(cbr_period_control) #Module/UW/ROV/CTR set PoissonTraffic_ 1 @@ -22,13 +22,14 @@ proc createAUV { id } { # Module/UW/CBR set debug_ 0 #set cbr2_auv($id) [new Module/UW/ROV/CTR] - # TRAFFICO 3: ERROR AUV --> SUV + # 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(auv_period) Module/UW/AUV/ERR set PoissonTraffic_ 1 Module/UW/AUV/ERR set traffic_type_ 3 - Module/UW/AUV/ERR set debug_ 1 + Module/UW/AUV/ERR set debug_ 0 + Module/UW/AUV/ERR set log_flag_ 1 set auv_err($id) [new Module/UW/AUV/ERR] diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_coordinates.py b/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_coordinates.py index deff4265..a948e34c 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_coordinates.py +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_coordinates.py @@ -10,6 +10,15 @@ def plot_coordinates(file_path,x,y,z): y.append(float(row[1])) z.append(float(row[2])) +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])) + + @@ -17,27 +26,45 @@ def plot_coordinates(file_path,x,y,z): 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 = 'postion_log_a.csv' # Replace with your file pathplot_coordinates(file_path) +plot_coordinates_log(file_path,X_1,Y_1) +#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 = [] -Z_s = [] -file_path = 'test_uwauv0_results.csv' # Replace with your file pathplot_coordinates(file_path) -plot_coordinates(file_path,X_0,Y_0,Z_0) -file_path = 'test_uwauv1_results.csv' # Replace with your file pathplot_coordinates(file_path) -plot_coordinates(file_path,X_1,Y_1,Z_1) -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 = 'test_uwsuv_results.csv' # Replace with your file pathplot_coordinates(file_path) +#plot_coordinates(file_path,X_s,Y_s,Z_s) +file_path = '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) + + fig = plt.figure() -ax = fig.add_subplot(111, projection='3d') -ax.plot(X_0, Y_0, Z_0, label='auv_0') -ax.plot(X_1, Y_1, Z_1, label='auv_1') -ax.plot(X_s, Y_s, Z_s,label='sv') +ax = plt.subplot() +ax.plot(X_1, Y_1,'k.', label='auv_1') +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.set_zlabel('Z') ax.legend() #ax.set_zlabel('Z') plt.show() \ No newline at end of file diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/suv.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/suv.tcl deleted file mode 100644 index 70b7c379..00000000 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/suv.tcl +++ /dev/null @@ -1,159 +0,0 @@ -set scr [info script] -proc createSUV { id } { - - global ns suv_app suv_err position_suv node_suv udp_suv - global portnum_suv portnum2_suv ipr_suv ipif_suv - global channel channel_op propagation propagation_op data_mask data_mask_op - global phy_suv posdb_suv opt rvposx mll_suv mll_op_suv mac_suv - global mac_op_suv db_manager node_suv_coordinates - - set node_suv [$ns create-M_Node $opt(tracefile) $opt(cltracefile)] - - # TRAFFICO 2: CONTROL: SUV --> AUV - Module/UW/AUV/CTR set packetSize_ $opt(pktsize) - Module/UW/AUV/CTR set period_ $opt(ctr_period) - Module/UW/AUV/CTR set PoissonTraffic_ 1 - 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 suv_app($id1) [new Module/UW/AUV/CTR] - } - - # TRAFFICO 3: ERROR: AUV --> SUV - Module/UW/AUV/CER set packetSize_ $opt(pktsize) - Module/UW/AUV/CER set period_ $opt(ctr_period) - Module/UW/AUV/CER set PoissonTraffic_ 1 - Module/UW/AUV/CER set traffic_type_ 3 - Module/UW/AUV/CER set debug_ 1 - for {set id1 0} {$id1 <= $opt(n_auv)} {incr id1} { - set suv_err($id1) [new Module/UW/AUV/CER] - } - - set udp_suv [new Module/UW/UDP] - set ipr_suv [new Module/UW/StaticRouting] - set ipif_suv [new Module/UW/IP] - - set ctr_suv [new Module/UW/MULTI_TRAFFIC_RANGE_CTR] - - set mll_suv [new Module/UW/MLL] - set mac_suv [new Module/UW/CSMA_ALOHA] - Module/UW/PHYSICAL set BitRate_ $opt(bitrate) - Module/UW/PHYSICAL set MaxTxSPL_dB_ $opt(txpower) - set phy_suv [new Module/UW/PHYSICAL] - $mll_suv setstackid 1 - - set mll_op_suv [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_suv [new Module/UW/CSMA_ALOHA] - set phy_op_suv [new Module/UW/OPTICAL/PHY] - - #$node_suv addModule 8 $cbr_suv 0 "CBR1" - for {set id1 0} {$id1 <= $opt(n_auv)} {incr id1} { - #$node_suv addModule 8 $cbr_suv($id1) 0 "CBR1" - $node_suv addModule 8 $suv_app($id1) 0 "CBR1" - $node_suv addModule 8 $suv_err($id1) 0 "CBR2" - } - #$node_suv addModule 8 $cbr3_suv 0 "CBR3" - $node_suv addModule 7 $udp_suv 0 "UDP1" - $node_suv addModule 6 $ipr_suv 0 "IPR1" - $node_suv addModule 5 $ipif_suv 2 "IPF1" - - $node_suv addModule 4 $ctr_suv 2 "CTR" - - $node_suv addModule 3 $mll_suv 2 "MLL_LF" - $node_suv addModule 2 $mac_suv 2 "MAC_LF" - $node_suv addModule 1 $phy_suv 0 "PHY_LF" - - $node_suv addModule 3 $mll_op_suv 2 "MLL_OP" - $node_suv addModule 2 $mac_op_suv 2 "MAC_OP" - $node_suv addModule 1 $phy_op_suv 0 "PHY_OP" - - #$node_suv setConnection $cbr_suv $udp_suv 0 - for {set id1 0} {$id1 <= $opt(n_auv)} {incr id1} { - #$node_suv setConnection $cbr_suv($id1) $udp_suv 0 - $node_suv setConnection $suv_app($id1) $udp_suv 0 - $node_suv setConnection $suv_err($id1) $udp_suv 0 - } - #$node_suv setConnection $cbr3_suv $udp_suv 0 - $node_suv setConnection $udp_suv $ipr_suv 0 - $node_suv setConnection $ipr_suv $ipif_suv 2 - $node_suv setConnection $ipif_suv $ctr_suv 2 - - $node_suv setConnection $ctr_suv $mll_suv 2 - $node_suv setConnection $mll_suv $mac_suv 2 - $node_suv setConnection $mac_suv $phy_suv 2 - $node_suv addToChannel $channel $phy_suv 0 - - $node_suv setConnection $ctr_suv $mll_op_suv 2 - $node_suv setConnection $mll_op_suv $mac_op_suv 2 - $node_suv setConnection $mac_op_suv $phy_op_suv 2 - $node_suv addToChannel $channel_op $phy_op_suv 0 - - - - for {set id1 0} {$id1 <= $opt(n_auv)} {incr id1} { - #set portnum_suv($id1) [$udp_suv assignPort $cbr_suv($id1) ] - set portnum_suv($id1) [$udp_suv assignPort $suv_app($id1) ] - set portnum2_suv($id1) [$udp_suv assignPort $suv_err($id1) ] - } - #set portnum3_suv [$udp_suv assignPort $cbr3_suv ] - - if {$id > 254} { - puts "hostnum > 254!!! exiting" - exit - } - set tmp_ [expr $id + 1] - $ipif_suv addr $tmp_ - - set position_suv [new "Position/BM"] - $node_suv addPosition $position_suv - set posdb_suv [new "PlugIn/PositionDB"] - $node_suv addPlugin $posdb_suv 20 "PDB" - $posdb_suv addpos [$ipif_suv addr] $position_suv - - 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_suv setPropagation $propagation - $phy_suv setSpectralMask $data_mask - $phy_suv setInterference $interf_data - - $phy_op_suv setPropagation $propagation_op - $phy_op_suv setSpectralMask $data_mask_op - $phy_op_suv setInterference $interf_data_op - # $phy_op_leader useLUT - - $mac_suv $opt(ack_mode) - $mac_suv setMacAddr $tmp_ - $mac_suv initialize - - - $mac_op_suv setMacAddr $tmp_ - $mac_op_suv $opt(ack_mode) - $mac_op_suv initialize - -# MONITORING TRAFFIC - $ctr_suv addRobustLowLayer 1 "MLL_LF" - $ctr_suv addFastLowLayer 1 "MLL_OP" - $ctr_suv addUpLayer 1 "IPF1" - $ctr_suv setBufferFeatures 1 1000 0 - -# CONTROL TRAFFIC - $ctr_suv addRobustLowLayer 2 "MLL_LF" - $ctr_suv addFastLowLayer 2 "MLL_OP" - $ctr_suv addUpLayer 2 "IPF1" - $ctr_suv setBufferFeatures 2 1000 0 - -# #ERROR TRAFFIC - $ctr_suv addRobustLowLayer 3 "MLL_LF" - $ctr_suv addFastLowLayer 3 "MLL_OP" - $ctr_suv addUpLayer 3 "IPF1" - $ctr_suv setBufferFeatures 3 1000 0 - -} \ No newline at end of file diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl index 83bf9c2d..fe799b63 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl @@ -192,7 +192,7 @@ if {$opt(bash_parameters)} { } } -set opt(waypoint_file) "../dbs/wp_path/rov_path_simple.csv" +set opt(waypoint_file) "../dbs/wp_path/rov_path.csv" #random generator global defaultRNG @@ -235,7 +235,7 @@ Module/UW/AUV set debug_ 0 Module/UW/AUV/ERR set packetSize_ $opt(pktsize) Module/UW/AUV/ERR set period_ $opt(auv_period) Module/UW/AUV/ERR set PoissonTraffic_ 1 -Module/UW/AUV/ERR set debug_ 1 +Module/UW/AUV/ERR set debug_ 0 #UW/AUV/CERR Module/UW/AUV/CER set packetSize_ $opt(pktsize) @@ -314,12 +314,12 @@ $data_mask_op setBandwidth $opt(op_bw) ################################ source "auv.tcl" -source "suv.tcl" +source "asv.tcl" for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { createAUV $id1 } -createSUV $opt(n_auv) +createASV $opt(n_auv) #createROV [expr $opt(n_auv) + 1] ################################ @@ -327,21 +327,21 @@ createSUV $opt(n_auv) ################################ proc connectNodes {id1} { - global ipif_suv ipr_suv portnum_suv portnum_auv portnum2_suv portnum2_auv - global suv_app suv_err + 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 - $suv_app($id1) set destAddr_ [$ipif_auv($id1) addr] - $suv_app($id1) set destPort_ $portnum_auv($id1) + $asv_app($id1) set destAddr_ [$ipif_auv($id1) addr] + $asv_app($id1) set destPort_ $portnum_auv($id1) - $suv_err($id1) set destAddr_ [$ipif_auv($id1) addr] - $suv_err($id1) set destPort_ $portnum2_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_suv addr] - $auv_app($id1) set destPort_ $portnum_suv($id1) + $auv_app($id1) set destAddr_ [$ipif_asv addr] + $auv_app($id1) set destPort_ $portnum_asv($id1) - $auv_err($id1) set destAddr_ [$ipif_suv addr] - $auv_err($id1) set destPort_ $portnum2_suv($id1) + $auv_err($id1) set destAddr_ [$ipif_asv addr] + $auv_err($id1) set destPort_ $portnum2_asv($id1) } # Setup flows @@ -360,25 +360,25 @@ for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { # $mll_auv($id1) addentry [$ipif_auv($id2) addr] [$mac_auv($id2) addr] # $mll_op_auv($id1) addentry [$ipif_auv($id2) addr] [$mac_op_auv($id2) addr] #} - $mll_auv($id1) addentry [$ipif_suv addr] [$mac_suv addr] + $mll_auv($id1) addentry [$ipif_asv addr] [$mac_asv addr] # $mll_diver($id1) addentry [$ipif_rov addr] [$mac_rov addr] - $mll_op_auv($id1) addentry [$ipif_suv addr] [$mac_op_suv addr] + $mll_op_auv($id1) addentry [$ipif_asv addr] [$mac_op_asv addr] # $mll_hf_diver($id1) addentry [$ipif_rov addr] [$mac_rov addr] - $mll_suv addentry [$ipif_auv($id1) addr] [$mac_auv($id1) addr] - $mll_op_suv addentry [$ipif_auv($id1) addr] [$mac_op_auv($id1) 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] } -#$mll_suv addentry [$ipif_rov addr] [$mac_rov addr] -#$mll_op_suv addentry [$ipif_rov addr] [$mac_op_rov addr] +#$mll_asv addentry [$ipif_rov addr] [$mac_rov addr] +#$mll_op_asv addentry [$ipif_rov addr] [$mac_op_rov addr] #$mll_rov addentry [$ipif_leader addr] [$mac_leader addr] #$mll_op_rov addentry [$ipif_leader addr] [$mac_op_leader addr] Position/UWSM debug_ 0 # Setup positions -set position_suv [new "Position/UWSM"] -$position_suv setX_ 0 -$position_suv setY_ 0 -$position_suv setZ_ -1 +set position_asv [new "Position/UWSM"] +$position_asv setX_ 0 +$position_asv setY_ 0 +$position_asv setZ_ -1 #$position_rov setX_ 0 #$position_rov setY_ 10 @@ -386,9 +386,9 @@ $position_suv setZ_ -1 for {set id 0} {$id < $opt(n_auv)} {incr id} { - #$cbr_suv($id) setPosition $position_suv - $suv_app($id) setPosition $position_suv - $suv_err($id) setPosition $position_suv 5 + #$cbr_asv($id) setPosition $position_asv + $asv_app($id) setPosition $position_asv + $asv_err($id) setPosition $position_asv Position/UWSM debug_ 0 @@ -407,8 +407,8 @@ for {set id 0} {$id < $opt(n_auv)} {incr id} { # Setup routing table for {set id 0} {$id < $opt(n_auv)} {incr id} { - $ipr_auv($id) addRoute [$ipif_suv addr] [$ipif_suv addr] - $ipr_suv addRoute [$ipif_auv($id) addr] [$ipif_auv($id) addr] + $ipr_auv($id) addRoute [$ipif_asv addr] [$ipif_asv addr] + $ipr_asv addRoute [$ipif_auv($id) addr] [$ipif_auv($id) addr] # $ipr2_diver($id) addRoute [$ipif2_rov addr] [$ipif2_leader addr] # $ipr2_leader addRoute [$ipif2_diver($id) addr] [$ipif2_diver($id) addr] @@ -432,7 +432,7 @@ foreach line $data { if {[regexp {^(.*),(.*),(.*),(.*)$} $line -> t x y z]} { $ns at $t "update_and_check" for {set id 0} {$id < $opt(n_auv)} {incr id} { - $ns at $t "$suv_app($id) sendPosition [expr $x*($id*(-2))+$x] [expr $y*($id*(-2))+$y] [expr $z]" + $ns at $t "$asv_app($id) sendPosition [expr $x*($id*(-2))+$x] [expr $y*($id*(-2))+$y] [expr $z]" } } } @@ -440,15 +440,15 @@ foreach line $data { -#$ns at $opt(starttime) "$cbr3_suv($opt(n_auv)) start" -#$ns at $opt(stoptime) "$cbr3_suv($opt(n_auv)) stop" +#$ns at $opt(starttime) "$cbr3_asv($opt(n_auv)) start" +#$ns at $opt(stoptime) "$cbr3_asv($opt(n_auv)) stop" for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { - #$ns at $opt(starttime) "$cbr_suv($id1) start" - #$ns at $opt(stoptime) "$cbr_suv($id1) stop" + #$ns at $opt(starttime) "$cbr_asv($id1) start" + #$ns at $opt(stoptime) "$cbr_asv($id1) stop" - $ns at $opt(starttime) "$suv_app($id1) start" - $ns at $opt(stoptime) "$suv_app($id1) stop" + $ns at $opt(starttime) "$asv_app($id1) start" + $ns at $opt(stoptime) "$asv_app($id1) stop" $ns at $opt(starttime) "$auv_app($id1) start" $ns at $opt(stoptime) "$auv_app($id1) stop" @@ -456,8 +456,8 @@ for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { $ns at $opt(starttime) "$auv_err($id1) start" $ns at $opt(stoptime) "$auv_err($id1) stop" - $ns at $opt(starttime) "$suv_err($id1) start" - $ns at $opt(stoptime) "$suv_err($id1) stop" + $ns at $opt(starttime) "$asv_err($id1) start" + $ns at $opt(stoptime) "$asv_err($id1) stop" #$ns at $opt(starttime) "$cbr3_auv($id1) start" #$ns at $opt(stoptime) "$cbr3_auv($id1) stop" @@ -471,36 +471,36 @@ for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { } -#$ns at $opt(starttime) "$mac_suv start" -#$ns at $opt(stoptime) "$mac_suv stop" +#$ns at $opt(starttime) "$mac_asv start" +#$ns at $opt(stoptime) "$mac_asv stop" -#$ns at $opt(starttime) "$mac_op_suv start" -#$ns at $opt(stoptime) "$mac_op_suv stop" +#$ns at $opt(starttime) "$mac_op_asv start" +#$ns at $opt(stoptime) "$mac_op_asv stop" proc update_and_check {} { set outfile_auv0 [open "test_uwauv0_results.csv" "a"] set outfile_auv1 [open "test_uwauv1_results.csv" "a"] - set outfile_suv [open "test_uwsuv_results.csv" "a"] - global position_auv position_suv auv_app suv_app opt n_auv auv_err suv_err + 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 - # $position_suv update + # $position_asv update # puts $outfile "positions AUV: x( $id1 ) = [$auv_app($id1) getX], y = [$auv_app($id1) getY], z = [$auv_app($id1) getZ]" # puts $outfile "positions AUV_ERR: x( $id1 ) = [$auv_err($id1) getX], y = [$auv_err($id1) getY], z = [$auv_err($id1) getZ]" #} $position_auv(0) update $position_auv(1) update - $position_suv update + $position_asv update - puts $outfile_auv0 "[$auv_app(0) getX],[$auv_app(0) getY],[$auv_app(0) getZ],[$auv_app(0) getSpeed]" - puts $outfile_auv1 "[$auv_app(1) getX],[$auv_app(1) getY],[$auv_app(1) getZ],[$auv_app(1) getSpeed]" - puts $outfile_suv "[$suv_app(0) getX],[$suv_app(0) getY],[$suv_app(0) getZ],[$auv_app(0) getSpeed]" + puts $outfile_auv0 "[$auv_app(0) getX],[$auv_app(0) getY],[$auv_app(0) getZ]" + puts $outfile_auv1 "[$auv_app(1) getX],[$auv_app(1) getY],[$auv_app(1) getZ]" + puts $outfile_asv "[$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_auv0 close $outfile_auv1 - close $outfile_suv + close $outfile_asv } ### @@ -511,15 +511,15 @@ proc update_and_check {} { proc finish {} { global ns opt n_auv global mac propagation phy_data channel db_manager propagation - global node_suv_coordinates - global ipr_suv ipif_suv udp_suv phy - global suv_app suv_err + 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_suv_stats tmp_node_suv_stats ipif_auv ipif_suv + global node_asv_stats tmp_node_asv_stats ipif_auv ipif_asv puts "---------------------------------------------------------------------" puts "Simulation summary" - puts "Leader addr = [$ipif_suv addr]" + puts "Leader addr = [$ipif_asv addr]" for {set i 0} {$i < $opt(n_auv)} {incr i} { puts "Diver addr = [$ipif_auv($i) addr]" #puts "Packets in buffer [$mac_auv($i) get_buffer_size]" @@ -546,21 +546,21 @@ proc finish {} { for {set i 0} {$i < $opt(n_auv)} {incr i} { - set cbr_throughput [$suv_app($i) getthr] + set cbr_throughput [$asv_app($i) getthr] set cbr_sent_pkts [$auv_app($i) getsentpkts] - set cbr_rcv_pkts [$suv_app($i) getrecvpkts] + set cbr_rcv_pkts [$asv_app($i) getrecvpkts] set cbr_throughput2 [$auv_app($i) getthr] - set cbr_sent_pkts2 [$suv_app($i) getsentpkts] + set cbr_sent_pkts2 [$asv_app($i) getsentpkts] set cbr_rcv_pkts2 [$auv_app($i) getrecvpkts] - set cbr_throughput4 [$suv_err($i) getthr] + set cbr_throughput4 [$asv_err($i) getthr] set cbr_sent_pkts4 [$auv_err($i) getsentpkts] - set cbr_rcv_pkts4 [$suv_err($i) getrecvpkts] + set cbr_rcv_pkts4 [$asv_err($i) getrecvpkts] - #set cbr_throughput3 [$cbr3_suv($i) getthr] + #set cbr_throughput3 [$cbr3_asv($i) getthr] #set cbr_sent_pkts3 [$cbr3_auv($i) getsentpkts] - #set cbr_rcv_pkts3 [$cbr3_suv($i) getrecvpkts] + #set cbr_rcv_pkts3 [$cbr3_asv($i) getrecvpkts] set sum_cbr_throughput [expr $sum_cbr_throughput + $cbr_throughput] set sum_cbr_sent_pkts [expr $sum_cbr_sent_pkts + $cbr_sent_pkts] @@ -575,22 +575,22 @@ proc finish {} { set sum_cbr_rcv_pkts4 [expr $sum_cbr_rcv_pkts4 + $cbr_rcv_pkts4] } - #set sum_cbr_sent_pkts [expr $sum_cbr_sent_pkts + [$cbr_suv($opt(n_auv)) getsentpkts]] - #set sum_cbr_sent_pkts3 [expr $sum_cbr_sent_pkts3 + [$cbr3_suv getsentpkts]] + #set sum_cbr_sent_pkts [expr $sum_cbr_sent_pkts + [$cbr_asv($opt(n_auv)) getsentpkts]] + #set sum_cbr_sent_pkts3 [expr $sum_cbr_sent_pkts3 + [$cbr3_asv getsentpkts]] - #set sum_cbr_rcv_pkts [expr $sum_cbr_rcv_pkts + [$cbr_suv($opt(n_auv)) getrecvpkts]] - #set sum_cbr_rcv_pkts3 [expr $sum_cbr_rcv_pkts3 + [$cbr3_suv($opt(n_auv)) getrecvpkts]] + #set sum_cbr_rcv_pkts [expr $sum_cbr_rcv_pkts + [$cbr_asv($opt(n_auv)) getrecvpkts]] + #set sum_cbr_rcv_pkts3 [expr $sum_cbr_rcv_pkts3 + [$cbr3_asv($opt(n_auv)) getrecvpkts]] - #set sum_cbr_throughput [expr $sum_cbr_throughput + [$cbr_suv($opt(n_auv)) getthr]] - #set sum_cbr_throughput3 [expr $sum_cbr_throughput3 + [$cbr3_suv($opt(n_auv)) getthr]] + #set sum_cbr_throughput [expr $sum_cbr_throughput + [$cbr_asv($opt(n_auv)) getthr]] + #set sum_cbr_throughput3 [expr $sum_cbr_throughput3 + [$cbr3_asv($opt(n_auv)) getthr]] - #set sum_cbr_throughput2 [expr [$cbr2_suv(0) getthr] + $sum_cbr_throughput2] - #set sum_cbr_rcv_pkts2 [expr [$cbr2_suv(0) getrecvpkts] + $sum_cbr_rcv_pkts2] - #set sum_cbr_sent_pkts2 [expr $sum_cbr_sent_pkts2 + [$cbr2_suv($opt(n_auv)) getsentpkts]] + #set sum_cbr_throughput2 [expr [$cbr2_asv(0) getthr] + $sum_cbr_throughput2] + #set sum_cbr_rcv_pkts2 [expr [$cbr2_asv(0) getrecvpkts] + $sum_cbr_rcv_pkts2] + #set sum_cbr_sent_pkts2 [expr $sum_cbr_sent_pkts2 + [$cbr2_asv($opt(n_auv)) getsentpkts]] - set ipheadersize [$ipif_suv getipheadersize] - set udpheadersize [$udp_suv getudpheadersize] - set cbrheadersize [$suv_app(0) getcbrheadersize] + set ipheadersize [$ipif_asv getipheadersize] + set udpheadersize [$udp_asv getudpheadersize] + set cbrheadersize [$asv_app(0) getcbrheadersize] puts "IP Pkt Header Size : $ipheadersize" From d1cd7b49643e15f8facd503f37a413aba2944e21 Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Fri, 9 Jun 2023 17:21:22 +0200 Subject: [PATCH 07/36] new mobility model with error management --- DESERT_Addons/uwauv/Makefile.am | 2 +- DESERT_Addons/uwauv/m4/desert.m4 | 9 +- DESERT_Addons/uwauv/uwauv-init.tcl | 1 + DESERT_Framework/.addon.list | 1 + DESERT_Framework/DESERT/Makefile.am | 1 + DESERT_Framework/DESERT/configure.ac | 2 + .../DESERT/mobility/uwsmeposition/Makefile.am | 59 +++++ .../DESERT/mobility/uwsmeposition/initlib.cpp | 79 +++---- .../uwsmeposition/uwsmeposition-default.tcl | 33 +++ .../mobility/uwsmeposition/uwsmeposition.cpp | 206 ++++++++++++++++++ .../mobility/uwsmeposition/uwsmeposition.h | 169 ++++++++++++++ .../mobility/uwsmposition/uwsmposition.h | 6 +- .../DESERT/samples/desert_samples/AUV/asv.tcl | 4 +- .../DESERT/samples/desert_samples/AUV/auv.tcl | 16 +- .../AUV/test_uwmulti_traffic_auv.tcl | 34 +-- 15 files changed, 542 insertions(+), 80 deletions(-) create mode 100644 DESERT_Framework/DESERT/mobility/uwsmeposition/Makefile.am rename DESERT_Addons/uwauv/uwauvctr-tracer.cc => DESERT_Framework/DESERT/mobility/uwsmeposition/initlib.cpp (60%) create mode 100644 DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition-default.tcl create mode 100644 DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.cpp create mode 100644 DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.h diff --git a/DESERT_Addons/uwauv/Makefile.am b/DESERT_Addons/uwauv/Makefile.am index 98797b60..aac19869 100644 --- a/DESERT_Addons/uwauv/Makefile.am +++ b/DESERT_Addons/uwauv/Makefile.am @@ -31,7 +31,7 @@ AM_CXXFLAGS = -Wall -ggdb3 lib_LTLIBRARIES = libuwauv.la -libuwauv_la_SOURCES = uwauv-module.cc uwauverror-module.cc uwauv-tracer.cc uwauv-module.h uwauverror-module.h uwauv-packet.h uwauvctr-module.cc uwauvctrer-module.cc uwauvctr-tracer.cc uwauvctr-module.h uwauvctrer-module.h initlib.cc +libuwauv_la_SOURCES = uwauv-module.cc uwauverror-module.cc uwauv-module.h uwauverror-module.h uwauv-packet.h uwauvctr-module.cc uwauvctrer-module.cc uwauvctr-module.h uwauvctrer-module.h initlib.cc libuwauv_la_CPPFLAGS = @NS_CPPFLAGS@ @NSMIRACLE_CPPFLAGS@ @DESERT_CPPFLAGS@ libuwauv_la_LDFLAGS = @NS_LDFLAGS@ @NSMIRACLE_LDFLAGS@ @DESERT_LDFLAGS@ @DESERT_LDFLAGS_BUILD@ diff --git a/DESERT_Addons/uwauv/m4/desert.m4 b/DESERT_Addons/uwauv/m4/desert.m4 index c2e0ecd4..fcd5a26e 100644 --- a/DESERT_Addons/uwauv/m4/desert.m4 +++ b/DESERT_Addons/uwauv/m4/desert.m4 @@ -51,7 +51,8 @@ AC_DEFUN([AC_ARG_WITH_DESERT],[ application/uwcbr \ network/uwip \ transport/uwudp \ - mobility/uwsmposition + mobility/uwsmposition \ + mobility/uwsmeposition do echo "considering dir \"$dir\"" DESERT_CPPFLAGS="$DESERT_CPPFLAGS -I${DESERT_PATH}/${dir}" @@ -62,7 +63,8 @@ AC_DEFUN([AC_ARG_WITH_DESERT],[ uwcbr \ uwip \ uwudp \ - uwsmposition + uwsmposition \ + uwsmeposition do DESERT_LIBADD="$DESERT_LIBADD -l${lib}" done @@ -101,7 +103,8 @@ AC_DEFUN([AC_ARG_WITH_DESERT_BUILD],[ application/uwcbr \ network/uwip \ transport/uwudp \ - mobility/uwsmposition + mobility/uwsmposition \ + mobility/uwsmeposition do echo "considering dir \"$dir\"" DESERT_LDFLAGS_BUILD="$DESERT_LDFLAGS_BUILD -L${DESERT_PATH_BUILD}/${dir}" diff --git a/DESERT_Addons/uwauv/uwauv-init.tcl b/DESERT_Addons/uwauv/uwauv-init.tcl index f32cdfd4..39db2a7d 100644 --- a/DESERT_Addons/uwauv/uwauv-init.tcl +++ b/DESERT_Addons/uwauv/uwauv-init.tcl @@ -107,5 +107,6 @@ Module/UW/AUV/CER instproc init {args} { #} Position/UWSM set debug_ 0 +Position/UWSME set debug_ 0 PlugIn/PositionDB set debug_ 0 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..b23ab573 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/uwsmeposition \ interference/uwinterference \ interference/uwinterferenceofdm \ propagation/uwoptical_propagation \ diff --git a/DESERT_Framework/DESERT/configure.ac b/DESERT_Framework/DESERT/configure.ac index a5f6e70f..7eceaaf3 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/uwsmeposition' 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/uwsmeposition/Makefile interference/uwinterference/Makefile interference/uwinterferenceofdm/Makefile propagation/uwoptical_propagation/Makefile diff --git a/DESERT_Framework/DESERT/mobility/uwsmeposition/Makefile.am b/DESERT_Framework/DESERT/mobility/uwsmeposition/Makefile.am new file mode 100644 index 00000000..63939021 --- /dev/null +++ b/DESERT_Framework/DESERT/mobility/uwsmeposition/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 = libuwsmeposition.la +check_PROGRAMS = + +SUBDIRS = + +TESTS = + +libuwsmeposition_la_SOURCES = initlib.cpp\ + uwsmeposition-default.tcl\ + uwsmeposition.cpp + +libuwsmeposition_la_CPPFLAGS = @NS_CPPFLAGS@ @NSMIRACLE_CPPFLAGS@ @DESERT_CPPFLAGS@ +libuwsmeposition_la_LDFLAGS = @NS_LDFLAGS@ @NSMIRACLE_LDFLAGS@ @DESERT_LDFLAGS@ +libuwsmeposition_la_LIBADD = @NS_LIBADD@ @NSMIRACLE_LIBADD@ @DESERT_LIBADD@ + +nodist_libuwsmeposition_la_SOURCES = InitTcl.cc + + +BUILT_SOURCES = InitTcl.cc + +CLEANFILES = InitTcl.cc + +TCL_FILES = uwsmeposition-default.tcl + +InitTcl.cc: Makefile $(TCL_FILES) + cat $(VPATH)/$(TCL_FILES) | @TCL2CPP@ UwSMEPositionTclCode > InitTcl.cc + +EXTRA_DIST = $(TCL_FILES) diff --git a/DESERT_Addons/uwauv/uwauvctr-tracer.cc b/DESERT_Framework/DESERT/mobility/uwsmeposition/initlib.cpp similarity index 60% rename from DESERT_Addons/uwauv/uwauvctr-tracer.cc rename to DESERT_Framework/DESERT/mobility/uwsmeposition/initlib.cpp index 6551be35..edf7c133 100644 --- a/DESERT_Addons/uwauv/uwauvctr-tracer.cc +++ b/DESERT_Framework/DESERT/mobility/uwsmeposition/initlib.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2014 Regents of the SIGNET lab, University of Padova. +// 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 @@ -10,66 +10,47 @@ // 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 +// 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 +// 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 uwauvtct-tracer.cc + * @file mobility/uwsmeposition/initlib.cpp * @author Filippo Campagnaro * @version 1.0.0 - * - * \brief Provides a tracer class for UWAUVCTR packets. - * - * Provides a tracer class for UWAUVCTR packets. + * + * \brief Provides the initialization of uwsmeposition libraries. + * + * Provides the initialization of uwsmeposition libraries. */ +#include "uwsmeposition.h" -#include "uwauvctr-module.h" +#include -/** - * Class that defines a tracer for hdr_uwAUV_ctr packets. - */ -class UWAUVCtrTracer : public Tracer { -public: - UWAUVCtrTracer(); -protected: - void format(Packet *p, SAP* sap); -}; +extern EmbeddedTcl UwSMEPositionTclCode; -UWAUVCtrTracer::UWAUVCtrTracer() : Tracer(4) { +extern "C" int +Uwsmeposition_Init() +{ + UwSMEPositionTclCode.load(); + return 0; } -void UWAUVCtrTracer::format(Packet *p, SAP *sap) { - hdr_cmn *ch = hdr_cmn::access(p); - - if (ch->ptype() != PT_UWCBR) - return; - - hdr_uwAUV_ctr *uwAUVh = HDR_UWAUV_CTR(p); +extern "C" int +Cygsmposition_Init() +{ + Uwsmeposition_Init(); } - -extern "C" int UwAUVCtrtracer_Init() { - SAP::addTracer(new UWAUVCtrTracer); - return 0; -} - -extern "C" int CyguwAUVCtrtracer_Init() { - UwAUVCtrtracer_Init(); - return 0; -} - - diff --git a/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition-default.tcl b/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition-default.tcl new file mode 100644 index 00000000..418fdc21 --- /dev/null +++ b/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition-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 uwsmeposition-defaults.tcl +# @author Filippo Campagnaro +# @version 1.0.0 + +Position/UWSME set debug_ 0 diff --git a/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.cpp b/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.cpp new file mode 100644 index 00000000..23b1c997 --- /dev/null +++ b/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.cpp @@ -0,0 +1,206 @@ +// +// 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 uwsmeposition.cpp +* @author Filippo Campagnaro +* @version 1.0.0 +* +* \brief Provides the UWSMEPosition class implementation. +* +* Provides the UWSMEPosition class implementation. +*/ + +#include +#include "uwsmeposition.h" + +/* ====================================================================== + TCL Hooks for the simulator + ====================================================================== */ +static class UWSMEPositionClass : public TclClass +{ +public: + UWSMEPositionClass() + : TclClass("Position/UWSME") + { + } + TclObject * + create(int, const char *const *) + { + return (new UWSMEPosition()); + } +} class_uwsmeposition; + +UWSMEPosition::UWSMEPosition() + : UWSMPosition() + , alarm_mode(0) +{ + bind("debug_", &debug_); +} + +UWSMEPosition::~UWSMEPosition() +{ +} + +int +UWSMEPosition::command(int argc, const char *const *argv) +{ + Tcl &tcl = Tcl::instance(); + if (argc == 6) { + if (strcasecmp(argv[1], "setdest") == 0) { + if (debug_) + cerr << NOW << "UWSMEPosition::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 (argc == 5) { + if (strcasecmp(argv[1], "setdest") == 0) { + if (debug_) + cerr << NOW << "UWSMEPosition::command(setdest, " << argv[2] + << ", " << argv[3] << ", " << argv[4] << ")" << endl; + setdest(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 +UWSMEPosition::setdest( + double x_dest, double y_dest, double z_dest, double spead_setted) +{ + if (alarm_mode){ + UWSMPosition::setdest(x_dest,y_dest,z_dest); + if (debug_) + printf("New pos (%f,%f,%f), dest(%f,%f,%f), speed blocked by ALARM\n", + getX(), + getY(), + getZ(), + getXdest(), + getYdest(), + getZdest()); + }else{ + UWSMPosition::setdest(x_dest,y_dest,z_dest,spead_setted); + } + +} + +void +UWSMEPosition::setdest(double x_dest, double y_dest, double z_dest) +{ + UWSMPosition::setdest(x_dest,y_dest,z_dest); +} + +void +UWSMEPosition::update(double now) +{ + UWSMPosition::update(now); +} +/* +double +UWSMEPosition::getX() +{ + double now = Scheduler::instance().clock(); + if ((trgTime_ > 0.) && (now > lastUpdateTime_ + 1e-6)) + update(now); + return (x_); +} + +void +UWSMEPosition::setX(double x) +{ + x_ = x; + Xdest_ = x; + Xsorg_ = x; +} +void +UWSMEPosition::setY(double y) +{ + y_ = y; + Ydest_ = y; + Ysorg_ = y; +} +void +UWSMEPosition::setZ(double z) +{ + z_ = z; + Zdest_ = z; + Zsorg_ = z; +} +double +UWSMEPosition::getY() +{ + double now = Scheduler::instance().clock(); + if ((trgTime_ > 0.) && (now > lastUpdateTime_ + 1e-6)) + update(now); + return (y_); +} + +double +UWSMEPosition::getZ() +{ + double now = Scheduler::instance().clock(); + if ((trgTime_ > 0.) && (now > lastUpdateTime_ + 1e-6)) + update(now); + return (z_); +} + +double UWSMEPosition::getXdest() const +{ + return Xdest_; +} + +double UWSMEPosition::getYdest() const +{ + return Ydest_; +} + +double UWSMEPosition::getZdest() const +{ + return Zdest_; +} + +double UWSMEPosition::getSpeed() const +{ + return speed_; +}*/ + +void +UWSMEPosition::setAlarm(bool alarm) +{ + alarm_mode = alarm; +} diff --git a/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.h b/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.h new file mode 100644 index 00000000..80bcfa2e --- /dev/null +++ b/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.h @@ -0,0 +1,169 @@ +// +// 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 uwsmeposition.h + * @author Filippo Campagnaro + * @version 1.0.0 + * + * \brief Provides the definition of the class UWSMEPosition. + * + * Provides the definition of the class UWSMEPosition. + * 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. + * 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 + +#define sgn(x) (((x) == 0.0) ? 0.0 : ((x) / fabs(x))) +#define pi (4 * atan(1.0)) + +class UWSMEPosition : public UWSMPosition +{ +public: + /** + * Constructor + */ + UWSMEPosition(); + /** + * Destructor + */ + virtual ~UWSMEPosition(); + /** + * Method that return the current projection of the node on the x-axis. + * If it's necessary (updating time ia expired), update the position values + * before returns it. + */ + //virtual double getX(); + /** + * Method that return the current projection of the node on the y-axis. + * If it's necessary (updating time ia expired), update the position values + * before returns it. + */ +// virtual double getY(); + + /** + * Method that return the current projection of the node on the z-axis. + * If it's necessary (updating time ia expired), update the position values + * before returns it. + */ + //virtual double getZ(); + + /** + * Method that return the x cooridnate of the destination point. + */ + //virtual double getXdest() const; + + /** + * Method that return the y cooridnate of the destination point. + */ + //virtual double getYdest() const; + + /** + * Method that return the z cooridnate of the destination point. + */ + //virtual double getZdest() const; + + /** + * Method that return the actual speed. + */ + //double getSpeed() const; + + /** + * 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 + * + * + * 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); + virtual void setdest( + double x_dest, double y_dest, double z_dest, double spead); + virtual void setdest(double x_dest, double y_dest, double z_dest); + /* + virtual void setX(double x); + virtual void setY(double y); + virtual void setZ(double z);*/ + virtual void setAlarm(bool alarm); + +protected: + /** + * Method that updates both the position coordinates + */ + virtual void update(double now); + +private: + + + /*double trgTime_; /// time in which the TCL command setdest is invoked + double lastUpdateTime_; /// time last updated of the coordinates was + /// computed + double Xdest_; /// position on the x-axis of the destination point + double Ydest_; /// position on the y-axis of the destination point + double Zdest_; /// position on the z-axis of the destination point + double Xsorg_; /// position on the x-axis of the starting point (when the + /// TCL command setdest is invoked) + double Ysorg_; /// position on the y-axis of the starting point (when the + /// TCL command setdest is invoked) + double Zsorg_; /// position on the z-axis of the starting point (when the + /// TCL command setdest is invoked) + double speed_; /// speed of the node + */ + + int debug_; + + bool alarm_mode; +}; + +#endif diff --git a/DESERT_Framework/DESERT/mobility/uwsmposition/uwsmposition.h b/DESERT_Framework/DESERT/mobility/uwsmposition/uwsmposition.h index 57a63fe6..fb9d78d5 100644 --- a/DESERT_Framework/DESERT/mobility/uwsmposition/uwsmposition.h +++ b/DESERT_Framework/DESERT/mobility/uwsmposition/uwsmposition.h @@ -134,12 +134,16 @@ 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); + +private: + double trgTime_; /// time in which the TCL command setdest is invoked double lastUpdateTime_; /// time last updated of the coordinates was /// computed diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl index a2070090..a84755f6 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl @@ -22,10 +22,10 @@ proc createASV { id } { # TRAFFICO 3: ERROR: AUV --> ASV Module/UW/AUV/CER set packetSize_ $opt(pktsize) - Module/UW/AUV/CER set period_ $opt(ctr_period) + Module/UW/AUV/CER set period_ 500 Module/UW/AUV/CER set PoissonTraffic_ 1 Module/UW/AUV/CER set traffic_type_ 3 - Module/UW/AUV/CER set debug_ 0 + Module/UW/AUV/CER set debug_ 0 Module/UW/AUV/CER set log_flag_ 1 for {set id1 0} {$id1 <= $opt(n_auv)} {incr id1} { set asv_err($id1) [new Module/UW/AUV/CER] diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl index 7342528f..12af1264 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl @@ -25,11 +25,11 @@ proc createAUV { id } { # 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(auv_period) + Module/UW/AUV/ERR set period_ 500 Module/UW/AUV/ERR set PoissonTraffic_ 1 - Module/UW/AUV/ERR set traffic_type_ 3 - Module/UW/AUV/ERR set debug_ 0 - Module/UW/AUV/ERR set log_flag_ 1 + Module/UW/AUV/ERR set traffic_type_ 3 + Module/UW/AUV/ERR set debug_ 0 + Module/UW/AUV/ERR set log_flag_ 1 set auv_err($id) [new Module/UW/AUV/ERR] @@ -114,11 +114,11 @@ proc createAUV { id } { set tmp_ [expr ($id) + 1] $ipif_auv($id) addr $tmp_ - set position_auv($id) [new "Position/UWSM"] ; #Position/BM (?) + 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 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_) diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl index fe799b63..25c105ff 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl @@ -94,6 +94,7 @@ load libuwudp.so load libuwcbr.so load libuwtdma.so load libuwsmposition.so +load libuwsmeposition.so load libuwinterference.so load libUwmStd.so load libUwmStdPhyBpskTracer.so @@ -126,7 +127,7 @@ $ns use-Miracle ################## set opt(n_auv) 2 ;# Number of Nodes set opt(starttime) 1 -set opt(stoptime) 100000 +set opt(stoptime) 6000 set opt(txduration) [expr $opt(stoptime) - $opt(starttime)] set opt(rngstream) 1 @@ -150,7 +151,7 @@ set opt(pktsize) 125 set opt(ctr_period) 60 set opt(pktsize_monitoring) 50 -set opt(auv_period) [expr $opt(tdma_frame)*2] +set opt(auv_period) 40 #set opt(pktsize_control) 100 #set opt(cbr_period_control) [expr $opt(cbr_period_monitoring)*4] @@ -192,7 +193,7 @@ if {$opt(bash_parameters)} { } } -set opt(waypoint_file) "../dbs/wp_path/rov_path.csv" +set opt(waypoint_file) "../dbs/wp_path/rov_path_simple.csv" #random generator global defaultRNG @@ -373,9 +374,9 @@ for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { #$mll_rov addentry [$ipif_leader addr] [$mac_leader addr] #$mll_op_rov addentry [$ipif_leader addr] [$mac_op_leader addr] -Position/UWSM debug_ 0 +Position/UWSME debug_ 1 # Setup positions -set position_asv [new "Position/UWSM"] +set position_asv [new "Position/UWSME"] $position_asv setX_ 0 $position_asv setY_ 0 $position_asv setZ_ -1 @@ -390,9 +391,9 @@ for {set id 0} {$id < $opt(n_auv)} {incr id} { $asv_app($id) setPosition $position_asv $asv_err($id) setPosition $position_asv - Position/UWSM debug_ 0 + Position/UWSME debug_ 1 - set position_auv($id) [new "Position/UWSM"] + set position_auv($id) [new "Position/UWSME"] #$position_auv($id) setX_ [expr -50 * (1 + $id % $opt(n_auv)/2) - 25 + 50 * rand()] $position_auv($id) setX_ 0 #$position_auv($id) setY_ [expr -50 + 100 * ($id%2) - 25 + 50 * rand()] @@ -405,6 +406,7 @@ for {set id 0} {$id < $opt(n_auv)} {incr 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] @@ -420,8 +422,7 @@ for {set id 0} {$id < $opt(n_auv)} {incr id} { # Start/Stop Timers # ##################### # Set here the timers to start and/or stop modules (optional) -# e.g., - +# e.g., set outfile [open "test_uwauv_results.csv" "w"] close $outfile @@ -430,7 +431,7 @@ 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" + $ns at $t "update_and_check $t" 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]" } @@ -438,8 +439,6 @@ foreach line $data { } - - #$ns at $opt(starttime) "$cbr3_asv($opt(n_auv)) start" #$ns at $opt(stoptime) "$cbr3_asv($opt(n_auv)) stop" @@ -477,7 +476,7 @@ for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { #$ns at $opt(starttime) "$mac_op_asv start" #$ns at $opt(stoptime) "$mac_op_asv stop" -proc update_and_check {} { +proc update_and_check {t} { set outfile_auv0 [open "test_uwauv0_results.csv" "a"] set outfile_auv1 [open "test_uwauv1_results.csv" "a"] set outfile_asv [open "test_uwasv_results.csv" "a"] @@ -493,14 +492,16 @@ proc update_and_check {} { $position_auv(1) update $position_asv update - puts $outfile_auv0 "[$auv_app(0) getX],[$auv_app(0) getY],[$auv_app(0) getZ]" - puts $outfile_auv1 "[$auv_app(1) getX],[$auv_app(1) getY],[$auv_app(1) getZ]" - puts $outfile_asv "[$asv_app(0) getX],[$asv_app(0) getY],[$asv_app(0) getZ]" + puts $outfile_auv0 "$t,[$auv_app(0) getX],[$auv_app(0) getY],[$auv_app(0) getZ]" + puts $outfile_auv1 "$t,[$auv_app(1) getX],[$auv_app(1) getY],[$auv_app(1) getZ]" + 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_auv0 close $outfile_auv1 close $outfile_asv + + } ### @@ -517,6 +518,7 @@ proc finish {} { global auv_app auv_err mac_auv global node_asv_stats tmp_node_asv_stats ipif_auv ipif_asv + puts "---------------------------------------------------------------------" puts "Simulation summary" puts "Leader addr = [$ipif_asv addr]" From 00bffb85fd4b47e48cf44a854285227f832bde6c Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Fri, 9 Jun 2023 17:22:12 +0200 Subject: [PATCH 08/36] correction alarm mode(static) --- DESERT_Addons/uwauv/uwauvctr-module.cc | 8 +-- DESERT_Addons/uwauv/uwauvctr-module.h | 10 +-- DESERT_Addons/uwauv/uwauvctrer-module.cc | 40 +++++++----- DESERT_Addons/uwauv/uwauvctrer-module.h | 16 +++-- DESERT_Addons/uwauv/uwauverror-module.cc | 22 +++++-- DESERT_Addons/uwauv/uwauverror-module.h | 15 ++--- .../desert_samples/AUV/plot_coordinates.py | 63 +++++++++++++++++-- 7 files changed, 124 insertions(+), 50 deletions(-) diff --git a/DESERT_Addons/uwauv/uwauvctr-module.cc b/DESERT_Addons/uwauv/uwauvctr-module.cc index 138b55ee..7fbb7b9d 100644 --- a/DESERT_Addons/uwauv/uwauvctr-module.cc +++ b/DESERT_Addons/uwauv/uwauvctr-module.cc @@ -69,7 +69,7 @@ static class UwAUVCtrModuleClass : public TclClass { } } class_module_uwAUV_ctr; -UwAUVCtrModule::UwAUVCtrModule(UWSMPosition* p) +UwAUVCtrModule::UwAUVCtrModule(UWSMEPosition* p) : UwCbrModule() , sn(0) , adaptiveRTO(0) @@ -99,7 +99,7 @@ UwAUVCtrModule::UwAUVCtrModule() //, rttAcksamples(0) { p = NULL; - UWSMPosition p = UWSMPosition(); + UWSMEPosition p = UWSMEPosition(); posit=&p; //posit = Position(); speed = 1; @@ -144,7 +144,7 @@ int UwAUVCtrModule::command(int argc, const char*const* argv) { } else if(argc == 3){ if (strcasecmp(argv[1], "setPosition") == 0) { - UWSMPosition* p = dynamic_cast (tcl.lookup(argv[2])); + UWSMEPosition* p = dynamic_cast (tcl.lookup(argv[2])); posit = p; return TCL_OK; } else if (strcasecmp(argv[1], "setSpeed") == 0) { @@ -196,7 +196,7 @@ void UwAUVCtrModule::transmit() { void UwAUVCtrModule::start() {} -void UwAUVCtrModule::setPosition(UWSMPosition* p){ +void UwAUVCtrModule::setPosition(UWSMEPosition* p){ posit = p; } diff --git a/DESERT_Addons/uwauv/uwauvctr-module.h b/DESERT_Addons/uwauv/uwauvctr-module.h index 5ca53ca4..58e88af9 100644 --- a/DESERT_Addons/uwauv/uwauvctr-module.h +++ b/DESERT_Addons/uwauv/uwauvctr-module.h @@ -47,7 +47,7 @@ #define UWAUV_CTR_MODULE_H #include #include "uwauv-packet.h" -#include "uwsmposition.h" +#include "uwsmeposition.h" #include "node-core.h" #include #define UWAUV_DROP_REASON_UNKNOWN_TYPE "UKT" /**< Reason for a drop in a UWAUV module. */ @@ -86,7 +86,7 @@ class UwAUVCtrModule : public UwCbrModule { /** * Constructor of UwAUVCtrModule class with position setting. */ - UwAUVCtrModule(UWSMPosition* p); + UwAUVCtrModule(UWSMEPosition* p); /** * Destructor of UwAUVCtrModule class. @@ -120,14 +120,14 @@ class UwAUVCtrModule : public UwCbrModule { * * @param Position * p Pointer to the AUVCtr position */ - virtual void setPosition(UWSMPosition* p); + virtual void setPosition(UWSMEPosition* p); /** * Returns the position of the AUVCtr * * @return the current AUVCtr position */ - inline UWSMPosition* getPosition() { return posit;} + inline UWSMEPosition* getPosition() { return posit;} /** * Returns the last AUV position monitored @@ -187,7 +187,7 @@ class UwAUVCtrModule : public UwCbrModule { protected: - UWSMPosition* posit; /**< Controller position.*/ + UWSMEPosition* 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.*/ diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.cc b/DESERT_Addons/uwauv/uwauvctrer-module.cc index 36624346..19393e43 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.cc +++ b/DESERT_Addons/uwauv/uwauvctrer-module.cc @@ -70,7 +70,7 @@ static class UwAUVCtrErModuleClass : public TclClass { } class_module_uwAUV_error; -UwAUVCtrErModule::UwAUVCtrErModule(UWSMPosition* p) +UwAUVCtrErModule::UwAUVCtrErModule(UWSMEPosition* p) : UwCbrModule() , ack(0) , last_sn_confirmed(0) @@ -79,11 +79,12 @@ UwAUVCtrErModule::UwAUVCtrErModule(UWSMPosition* p) , drop_old_waypoints(1) , log_flag(0) , pos_log(0) - , alarm_mode(false) + //, alarm_mode(false) , period(60) { posit=p; speed=5; + //alarm_mode = false; bind("ackTimeout_", (int*) &ackTimeout); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); bind("log_flag_", (int*) &log_flag ); @@ -104,15 +105,16 @@ UwAUVCtrErModule::UwAUVCtrErModule() , drop_old_waypoints(1) , log_flag(0) //, out_file_stats(0) - , alarm_mode(false) + //, alarm_mode(false) , period(60) { p = NULL; - UWSMPosition p = UWSMPosition(); + UWSMEPosition p = UWSMEPosition(); posit=&p; //posit = Position(); speed = 5; + //alarm_mode = false; bind("ackTimeout_", (int*) &ackTimeout); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); bind("log_flag_", (int*) &log_flag ); @@ -156,7 +158,7 @@ int UwAUVCtrErModule::command(int argc, const char*const* argv) { } else if(argc == 3){ if (strcasecmp(argv[1], "setPosition") == 0) { - UWSMPosition* p = dynamic_cast (tcl.lookup(argv[2])); + UWSMEPosition* p = dynamic_cast (tcl.lookup(argv[2])); posit = p; return TCL_OK; } else @@ -193,7 +195,7 @@ int UwAUVCtrErModule::command(int argc, const char*const* argv) { void UwAUVCtrErModule::start() {} -void UwAUVCtrErModule::setPosition(UWSMPosition* p){ +void UwAUVCtrErModule::setPosition(UWSMEPosition* p){ posit = p; } @@ -218,9 +220,9 @@ void UwAUVCtrErModule::initPkt(Packet* p) { uwAUVh->ack() = ack; ack = 0; - if(this->p == NULL){ + if(this->p == NULL){ //TO FIX - if ((abs(posit->getX() - x_auv) < 0.1) && (abs(posit->getY() - y_auv ) < 0.1)){ + if ((abs(posit->getX() - x_auv) < 1) && (abs(posit->getY() - y_auv ) < 1) && alarm_mode){ uwAUVh->speed() = 100; alarm_mode = false; @@ -230,7 +232,13 @@ void UwAUVCtrErModule::initPkt(Packet* p) { if (debug_) { std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) ERROR SOLVED" << std::endl; - } + } + + if (log_flag == 1) { + err_log.open("error_log.csv",std::ios_base::app); + err_log << NOW << "," << x_auv<<","<getX() - x_auv) < 0.1) && (abs(posit->getY() - y_auv ) < 0.1) ){ + }else if ((abs(posit->getX() - x_auv) < 1) && (abs(posit->getY() - y_auv ) < 1) && alarm_mode){ uwAUVh->speed() = 100; alarm_mode = false; uwAUVh->sn() = sn; + if (log_flag == 1) { + err_log.open("error_log.csv",std::ios_base::app); + err_log << NOW << "," << x_auv<<","<sn(); alarm_mode = true; - if (log_flag == 1) { - err_log.open("error_log.csv",std::ios_base::app); - err_log << NOW << "," << x_auv<<","< #include "uwauv-packet.h" -#include "uwsmposition.h" +#include "uwsmeposition.h" #include "node-core.h" #include #include @@ -89,7 +89,7 @@ class UwAUVCtrErModule : public UwCbrModule { /** * Constructor of UwAUVCtrModule class with position setting. */ - UwAUVCtrErModule(UWSMPosition* p); + UwAUVCtrErModule(UWSMEPosition* p); /** * Destructor of UwAUVCtrModule class. @@ -123,14 +123,14 @@ class UwAUVCtrErModule : public UwCbrModule { * * @param Position * p Pointer to the AUVCtr position */ - virtual void setPosition(UWSMPosition* p); + virtual void setPosition(UWSMEPosition* p); /** * Returns the position of the AUVCtr * * @return the current AUVCtr position */ - inline UWSMPosition* getPosition() { return posit;} + inline UWSMEPosition* getPosition() { return posit;} /** * Reset retransmissions @@ -191,7 +191,7 @@ class UwAUVCtrErModule : public UwCbrModule { protected: - UWSMPosition* posit; /**< Controller position.*/ + UWSMEPosition* 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 ack; @@ -207,8 +207,12 @@ class UwAUVCtrErModule : public UwCbrModule { std::ofstream pos_log; std::ofstream err_log; int ackTimeout; - bool alarm_mode; + static bool alarm_mode; + + //bool alarm_mode; }; +bool UwAUVCtrErModule::alarm_mode = false; + #endif // UWAUVCtr_MODULE_H diff --git a/DESERT_Addons/uwauv/uwauverror-module.cc b/DESERT_Addons/uwauv/uwauverror-module.cc index 77b59529..0c54fc66 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.cc +++ b/DESERT_Addons/uwauv/uwauverror-module.cc @@ -88,14 +88,16 @@ UwAUVErrorModule::UwAUVErrorModule() , log_flag(0) , out_file_stats(0) , period(60) + , error_p(0.2) { - UWSMPosition p = UWSMPosition(); + UWSMEPosition p = UWSMEPosition(); speed = 5; posit=&p; bind("ackTimeout_", (int*) &ackTimeout); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); bind("log_flag_", (int*) &log_flag ); bind("period_", (int*) &period ); + bind("error_p_", (int*) &error_p ); if (ackTimeout < 0) { cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" << std::endl; @@ -105,7 +107,7 @@ UwAUVErrorModule::UwAUVErrorModule() } -UwAUVErrorModule::UwAUVErrorModule(UWSMPosition* p) +UwAUVErrorModule::UwAUVErrorModule(UWSMEPosition* p) : UwCbrModule() , last_sn_confirmed(0) , sn(0) @@ -117,6 +119,7 @@ UwAUVErrorModule::UwAUVErrorModule(UWSMPosition* p) , log_flag(0) , out_file_stats(0) , period(60) + , error_p(0.2) { posit = p; speed = 5; @@ -124,6 +127,7 @@ UwAUVErrorModule::UwAUVErrorModule(UWSMPosition* p) bind("drop_old_waypoints_", (int*) &drop_old_waypoints); bind("log_flag_", (int*) &log_flag ); bind("period_", (int*) &period ); + bind("error_p_", (int*) &error_p ); if (ackTimeout < 0) { cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" << std::endl; @@ -136,7 +140,7 @@ UwAUVErrorModule::UwAUVErrorModule(UWSMPosition* p) UwAUVErrorModule::~UwAUVErrorModule() {} -void UwAUVErrorModule::setPosition(UWSMPosition* p){ +void UwAUVErrorModule::setPosition(UWSMEPosition* p){ posit = p; } @@ -173,7 +177,7 @@ int UwAUVErrorModule::command(int argc, const char*const* argv) { } else if(argc == 3){ if (strcasecmp(argv[1], "setPosition") == 0) { - UWSMPosition* p = dynamic_cast (tcl.lookup(argv[2])); + UWSMEPosition* p = dynamic_cast (tcl.lookup(argv[2])); posit=p; tcl.resultf("%s", "position Setted\n"); return TCL_OK; @@ -242,13 +246,16 @@ void UwAUVErrorModule::initPkt(Packet* p) { double randomValue = distrib(generator) ; - if(randomValue > 0.65){ + if(randomValue < error_p){ uwAUVh->x() = posit->getX(); uwAUVh->y() = posit->getY(); x_e = posit->getX(); y_e = posit->getY(); + posit->setdest(posit->getXdest(),posit->getYdest(),posit->getZdest(),0); + posit->setAlarm(true); + uwAUVh->sn() = ++sn; this->p = p; @@ -322,7 +329,10 @@ void UwAUVErrorModule::recv(Packet* p) { } else { //packet in order //TODO: When sv reaches the right position set speed > 0 if(uwAUVh->speed() == 100){ - //posit->setdest(posit->getXdest(),posit->getYdest(),posit->getZdest(),1); + + posit->setAlarm(false); + posit->setdest(posit->getXdest(),posit->getYdest(),posit->getZdest(),1); + if (debug_) { std::cout << NOW << " UwAUVErrModule::recv(Packet *p) error solved " "AUV can move again with speed=" << posit->getSpeed()<< std::endl; diff --git a/DESERT_Addons/uwauv/uwauverror-module.h b/DESERT_Addons/uwauv/uwauverror-module.h index 73b203e8..00fd9717 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.h +++ b/DESERT_Addons/uwauv/uwauverror-module.h @@ -45,7 +45,7 @@ #define UWAUVError_MODULE_H #include #include -#include "uwsmposition.h" +#include "uwsmeposition.h" #include #include #define UWAUVError_DROP_REASON_UNKNOWN_TYPE "UKT" /**< Reason for a drop in a UWAUV module. */ @@ -87,9 +87,9 @@ class UwAUVErrorModule : public UwCbrModule { /** * Constructor with position setting of UwAUVModule class. * - * @param UWSMPosition* p Pointer to the AUV position + * @param UWSMEPosition* p Pointer to the AUV position */ - UwAUVErrorModule(UWSMPosition* p); + UwAUVErrorModule(UWSMEPosition* p); /** * Destructor of UwAUVModule class. @@ -144,16 +144,16 @@ class UwAUVErrorModule : public UwCbrModule { /** * Sets the position of the AUV * - * @param UWSMPosition * p Pointer to the AUV position + * @param UWSMEPosition * p Pointer to the AUV position */ - virtual void setPosition(UWSMPosition* p); + virtual void setPosition(UWSMEPosition* p); /** * Returns the position of the AUV * * @return the current AUV position */ - inline UWSMPosition* getPosition() { return posit; } + inline UWSMEPosition* getPosition() { return posit; } /** * Returns the size in byte of a hdr_uwAUV_monitoring packet header. @@ -181,7 +181,7 @@ class UwAUVErrorModule : public UwCbrModule { enum UWAUV_ACK_POLICY { ACK_PIGGYBACK, ACK_IMMEDIATELY, ACK_PGBK_OR_TO }; - UWSMPosition* posit; /**< AUV position.*/ + UWSMEPosition* posit; /**< AUV position.*/ float speed; int last_sn_confirmed;/**< Sequence number of the last command Packete received.*/ int sn; @@ -208,6 +208,7 @@ class UwAUVErrorModule : public UwCbrModule { std::ofstream error_log; float x_e; float y_e; + float error_p; }; #endif // UWAUVError_MODULE_H diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_coordinates.py b/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_coordinates.py index a948e34c..c959f6ca 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_coordinates.py +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_coordinates.py @@ -1,14 +1,14 @@ import csv import matplotlib.pyplot as plt -def plot_coordinates(file_path,x,y,z): +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[0])) - y.append(float(row[1])) - z.append(float(row[2])) + x.append(float(row[1]) + float(row[2])) + y.append(float(row[2])) + t.append(float(row[0])) def plot_coordinates_log(file_path,x,y): @@ -18,6 +18,14 @@ def plot_coordinates_log(file_path,x,y): x.append(float(row[1])) y.append(float(row[2])) +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])) + @@ -55,11 +63,25 @@ def plot_coordinates_log(file_path,x,y): 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) + fig = plt.figure() ax = plt.subplot() -ax.plot(X_1, Y_1,'k.', label='auv_1') +ax.plot(X_1a, Y_1a,'y-', label='auv_1') 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') @@ -67,4 +89,33 @@ def plot_coordinates_log(file_path,x,y): ax.set_ylabel('Y') ax.legend() #ax.set_zlabel('Z') -plt.show() \ No newline at end of file +plt.show() + +Axis = [] +t = [] +file_path = 'postion_log_a.csv' # Replace with your file pathplot_coordinates(file_path) +plot_movement_log(file_path,t,Axis) + +s_ax = [] +s_t = [] +file_path = 'position_log.csv' # Replace with your file pathplot_coordinates(file_path) +plot_movement_log(file_path,s_t,s_ax) + +X_e_c = [] +Y_e_c = [] +file_path = 'error_calling_log.csv' # Replace with your file pathplot_coordinates(file_path) +plot_movement_log(file_path,X_e_c,Y_e_c) +X_e = [] +Y_e = [] +file_path = 'error_log.csv' # Replace with your file pathplot_coordinates(file_path) +plot_movement_log(file_path,X_e,Y_e) +fig = plt.figure() +ax = plt.subplot() +ax.plot(Z_1a, X_1a,'y-', label='auv_1') +ax.plot(Z_0, X_0,'m-', label='auv_1') +ax.plot(t, Axis,'k.', label='auv_1') +ax.plot(s_t, s_ax,'g--', label='asv') +ax.plot(X_e_c, Y_e_c, 'b^',label='error_called') +ax.plot(X_e, Y_e, 'rx',label='error_Solved') +ax.legend() +plt.show() From 9684565d11a5aa1c976dc1f7c4d89070b26b265f Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Sun, 11 Jun 2023 18:25:46 +0200 Subject: [PATCH 09/36] waypoints queue --- DESERT_Addons/uwauv/uwauv-module.cc | 16 +- DESERT_Addons/uwauv/uwauv-module.h | 14 +- DESERT_Addons/uwauv/uwauvctrer-module.cc | 61 ++++++-- DESERT_Addons/uwauv/uwauvctrer-module.h | 4 + DESERT_Addons/uwauv/uwauverror-module.cc | 7 + .../mobility/uwsmeposition/uwsmeposition.cpp | 140 +++++++++++++++++- .../mobility/uwsmeposition/uwsmeposition.h | 6 +- .../mobility/uwsmposition/uwsmposition.h | 6 +- .../AUV/test_uwmulti_traffic_auv.tcl | 4 +- 9 files changed, 226 insertions(+), 32 deletions(-) diff --git a/DESERT_Addons/uwauv/uwauv-module.cc b/DESERT_Addons/uwauv/uwauv-module.cc index 76dc76e7..5b5a6cf7 100644 --- a/DESERT_Addons/uwauv/uwauv-module.cc +++ b/DESERT_Addons/uwauv/uwauv-module.cc @@ -92,7 +92,7 @@ UwAUVModule::UwAUVModule() , log_flag(0) , out_file_stats(0) { - UWSMPosition p = UWSMPosition(); + UWSMEPosition p = UWSMEPosition(); posit=&p; bind("ackTimeout_", (int*) &ackTimeout); bind("ackPriority_", (int*) &ackPriority); @@ -106,7 +106,7 @@ UwAUVModule::UwAUVModule() } -UwAUVModule::UwAUVModule(UWSMPosition* p) +UwAUVModule::UwAUVModule(UWSMEPosition* p) : UwCbrModule() , last_sn_confirmed(0) , ack(0) @@ -135,7 +135,7 @@ UwAUVModule::UwAUVModule(UWSMPosition* p) UwAUVModule::~UwAUVModule() {} -void UwAUVModule::setPosition(UWSMPosition* p){ +void UwAUVModule::setPosition(UWSMEPosition* p){ posit = p; } @@ -169,7 +169,7 @@ int UwAUVModule::command(int argc, const char*const* argv) { } else if(argc == 3){ if (strcasecmp(argv[1], "setPosition") == 0) { - UWSMPosition* p = dynamic_cast (tcl.lookup(argv[2])); + UWSMEPosition* p = dynamic_cast (tcl.lookup(argv[2])); posit=p; tcl.resultf("%s", "position Setted\n"); return TCL_OK; @@ -201,12 +201,18 @@ int UwAUVModule::command(int argc, const char*const* argv) { 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); @@ -255,7 +261,7 @@ void UwAUVModule::recv(Packet* p) { } } else { //packet in order - posit->setdest(uwAUVh->x(),uwAUVh->y(),uwAUVh->z(),uwAUVh->speed()); + posit->adddest(uwAUVh->x(),uwAUVh->y(),uwAUVh->z(),uwAUVh->speed()); last_sn_confirmed = uwAUVh->sn(); } diff --git a/DESERT_Addons/uwauv/uwauv-module.h b/DESERT_Addons/uwauv/uwauv-module.h index c5a933e8..3e0b35da 100644 --- a/DESERT_Addons/uwauv/uwauv-module.h +++ b/DESERT_Addons/uwauv/uwauv-module.h @@ -45,7 +45,7 @@ #define UWAUV_MODULE_H #include #include -#include "uwsmposition.h" +#include "uwsmeposition.h" #include #include #define UWAUV_DROP_REASON_UNKNOWN_TYPE "UKT" /**< Reason for a drop in a UWAUV module. */ @@ -87,9 +87,9 @@ class UwAUVModule : public UwCbrModule { /** * Constructor with position setting of UwAUVModule class. * - * @param UWSMPosition* p Pointer to the AUV position + * @param UWSMEPosition* p Pointer to the AUV position */ - UwAUVModule(UWSMPosition* p); + UwAUVModule(UWSMEPosition* p); /** * Destructor of UwAUVModule class. @@ -131,16 +131,16 @@ class UwAUVModule : public UwCbrModule { /** * Sets the position of the AUV * - * @param UWSMPosition * p Pointer to the AUV position + * @param UWSMEPosition * p Pointer to the AUV position */ - virtual void setPosition(UWSMPosition* p); + virtual void setPosition(UWSMEPosition* p); /** * Returns the position of the AUV * * @return the current AUV position */ - inline UWSMPosition* getPosition() { return posit; } + inline UWSMEPosition* getPosition() { return posit; } /** * Returns the size in byte of a hdr_uwAUV_monitoring packet header. @@ -166,7 +166,7 @@ class UwAUVModule : public UwCbrModule { enum UWAUV_ACK_POLICY { ACK_PIGGYBACK, ACK_IMMEDIATELY, ACK_PGBK_OR_TO }; - UWSMPosition* posit; /**< AUV position.*/ + UWSMEPosition* 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.*/ //int send_ack_immediately; /**< Flag either to send acks immediately or not.*/ diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.cc b/DESERT_Addons/uwauv/uwauvctrer-module.cc index 19393e43..2f713438 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.cc +++ b/DESERT_Addons/uwauv/uwauvctrer-module.cc @@ -84,6 +84,8 @@ UwAUVCtrErModule::UwAUVCtrErModule(UWSMEPosition* p) { posit=p; speed=5; + x_sorg = posit->getX(); + y_sorg = posit->getY(); //alarm_mode = false; bind("ackTimeout_", (int*) &ackTimeout); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); @@ -112,6 +114,8 @@ UwAUVCtrErModule::UwAUVCtrErModule() p = NULL; UWSMEPosition p = UWSMEPosition(); posit=&p; + x_sorg = 0; + y_sorg = 0; //posit = Position(); speed = 5; //alarm_mode = false; @@ -212,17 +216,34 @@ void UwAUVCtrErModule::transmit() { 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); +} + void UwAUVCtrErModule::initPkt(Packet* p) { hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); hdr_uwcbr *uwcbrh = HDR_UWCBR(p); + bool found = false; uwAUVh->ack() = ack; ack = 0; - if(this->p == NULL){ //TO FIX + if(this->p == NULL){ + //TO FIX + + if ((abs(posit->getX() - x_auv) < 1) && (abs(posit->getY() - y_auv ) < 1) && alarm_mode){ //If in the right position + found = true; + } + //if((getDistance(x_sorg,y_sorg,x_auv,y_auv) < getDistance(posit->getX(),posit->getY(),x_auv,y_auv)) && alarm_mode){ //if the right position + // // has been already passed + // found = true; + //} + - if ((abs(posit->getX() - x_auv) < 1) && (abs(posit->getY() - y_auv ) < 1) && alarm_mode){ + if (found){ uwAUVh->speed() = 100; alarm_mode = false; @@ -231,7 +252,7 @@ void UwAUVCtrErModule::initPkt(Packet* p) { if (debug_) { std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) ERROR SOLVED" - << std::endl; + << std::endl; } if (log_flag == 1) { @@ -248,21 +269,32 @@ void UwAUVCtrErModule::initPkt(Packet* p) { } //Retransmission - }else if ((abs(posit->getX() - x_auv) < 1) && (abs(posit->getY() - y_auv ) < 1) && alarm_mode){ + }else{ + + if ((abs(posit->getX() - x_auv) < 1) && (abs(posit->getY() - y_auv ) < 1) && alarm_mode){ //If in the right position + found = true; + } + //if((getDistance(x_sorg,y_sorg,x_auv,y_auv) < getDistance(posit->getX(),posit->getY(),x_auv,y_auv)) && alarm_mode){ //if the right position + // // has been already passed + // found = true; + //} + + if (found){ - uwAUVh->speed() = 100; - alarm_mode = false; - uwAUVh->sn() = sn; + uwAUVh->speed() = 100; + alarm_mode = false; + uwAUVh->sn() = sn; - if (log_flag == 1) { + if (debug_) { + std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) Retransmission ERROR SOLVED" + << std::endl; + } + + if (log_flag == 1) { err_log.open("error_log.csv",std::ios_base::app); err_log << NOW << "," << x_auv<<","<getX(); + y_sorg = posit->getY(); } void UwAUVCtrErModule::recv(Packet* p, Handler* h) { @@ -319,6 +354,8 @@ void UwAUVCtrErModule::recv(Packet* p) { posit->setdest(x_auv,y_auv,posit->getZ(),1); last_sn_confirmed = uwAUVh->sn(); alarm_mode = true; + x_sorg = posit->getX(); + y_sorg = posit->getY(); } diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.h b/DESERT_Addons/uwauv/uwauvctrer-module.h index 395f3e46..96dc6940 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.h +++ b/DESERT_Addons/uwauv/uwauvctrer-module.h @@ -187,6 +187,8 @@ class UwAUVCtrErModule : public UwCbrModule { */ static inline int getAUVErrorHeaderSize() { return sizeof(hdr_uwAUV_error); } + float getDistance(float x_s,float y_s, float x_d, float y_d); + protected: @@ -208,6 +210,8 @@ class UwAUVCtrErModule : public UwCbrModule { std::ofstream err_log; int ackTimeout; static bool alarm_mode; + float x_sorg; + float y_sorg; //bool alarm_mode; diff --git a/DESERT_Addons/uwauv/uwauverror-module.cc b/DESERT_Addons/uwauv/uwauverror-module.cc index 0c54fc66..24025138 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.cc +++ b/DESERT_Addons/uwauv/uwauverror-module.cc @@ -205,13 +205,20 @@ int UwAUVErrorModule::command(int argc, const char*const* argv) { 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); } diff --git a/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.cpp b/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.cpp index 23b1c997..60c53c5a 100644 --- a/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.cpp +++ b/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.cpp @@ -80,6 +80,13 @@ UWSMEPosition::command(int argc, const char *const *argv) << ")" << 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 << "UWSMEPosition::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) { @@ -88,6 +95,12 @@ UWSMEPosition::command(int argc, const char *const *argv) << ", " << 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 << "UWSMEPosition::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) { @@ -119,6 +132,44 @@ UWSMEPosition::setdest( } +void +UWSMEPosition::adddest( + double x_dest, double y_dest, double z_dest, double speed_setted) +{ + if (!waypoints.empty()){ + waypoints.push_back({x_dest,y_dest,z_dest,speed_setted}); + if (debug_) + printf("New waypoint (%f,%f,%f)\n", + x_dest, + y_dest, + z_dest); + + }else{ + setdest(x_dest,y_dest,z_dest,speed_setted); + } + +} + +void +UWSMEPosition::adddest( + double x_dest, double y_dest, double z_dest) +{ + if (!waypoints.empty()){ + waypoints.push_back({x_dest,y_dest,z_dest}); + + if (debug_) + printf("New waypoint (%f,%f,%f)\n", + x_dest, + y_dest, + z_dest); + + }else{ + setdest(x_dest,y_dest,z_dest); + } + + +} + void UWSMEPosition::setdest(double x_dest, double y_dest, double z_dest) { @@ -128,7 +179,94 @@ UWSMEPosition::setdest(double x_dest, double y_dest, double z_dest) void UWSMEPosition::update(double now) { - UWSMPosition::update(now); + //UWSMPosition::update(now); + + if ((trgTime_ < 0.) || (now < lastUpdateTime_ + 1e-6)) + return; + + double gamma; + double theta; + double theta_den = sqrt(pow(Ydest_ - Ysorg_, 2.0) + //distance to destination + 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].size()>3){ + setdest(waypoints[0][0],waypoints[0][1],waypoints[0][2],waypoints[0][3]); + }else{ + setdest(waypoints[0][0],waypoints[0][1],waypoints[0][2]); + } + + waypoints.erase(waypoints.begin()); + if (debug_) + printf("New dest (%f,%f,%f) from waypoints list\n", + Xdest_, + Ydest_, + Zdest_); + } + + } else { + + theta = acos((Zdest_ - Zsorg_) / theta_den); + + if (Xdest_ - Xsorg_ == 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); + + if (pow(Ydest_ - Ysorg_, 2.0) + pow(Xdest_ - Xsorg_, 2.0) + + pow(Zdest_ - Zsorg_, 2.0) < + pow(x_ - Xsorg_, 2.0) + pow(y_ - Ysorg_, 2.0) + + pow(z_ - Zsorg_, 2.0)) { + x_ = Xdest_; + y_ = Ydest_; + z_ = Zdest_; + + if (!waypoints.empty()){ + if(waypoints[0].size()>3){ + setdest(waypoints[0][0],waypoints[0][1],waypoints[0][2],waypoints[0][3]); + }else{ + setdest(waypoints[0][0],waypoints[0][1],waypoints[0][2]); + } + + waypoints.erase(waypoints.begin()); + if (debug_) + printf("New dest (%f,%f,%f) from waypoints list\n", + Xdest_, + Ydest_, + Zdest_); + } + + } + if (debug_) + printf("New pos (%f,%f,%f), dest(%f,%f,%f), source(%f,%f,%f), speed %f sen(%f)=%f\n", + x_, + y_, + z_, + Xdest_, + Ydest_, + Zdest_, + Xsorg_, + Ysorg_, + Zsorg_, + speed_, + gamma, + sin(gamma)); + } + + lastUpdateTime_ = now; } /* double diff --git a/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.h b/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.h index 80bcfa2e..f843133a 100644 --- a/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.h +++ b/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.h @@ -51,6 +51,7 @@ #include #include +#include #define sgn(x) (((x) == 0.0) ? 0.0 : ((x) / fabs(x))) #define pi (4 * atan(1.0)) @@ -130,7 +131,10 @@ class UWSMEPosition : public UWSMPosition virtual int command(int argc, const char *const *argv); virtual void setdest( double x_dest, double y_dest, double z_dest, double spead); + virtual void adddest( + double x_dest, double y_dest, double z_dest, double spead); virtual void setdest(double x_dest, double y_dest, double z_dest); + virtual void adddest(double x_dest, double y_dest, double z_dest); /* virtual void setX(double x); virtual void setY(double y); @@ -160,7 +164,7 @@ class UWSMEPosition : public UWSMPosition /// TCL command setdest is invoked) double speed_; /// speed of the node */ - + std::vector> waypoints; int debug_; bool alarm_mode; diff --git a/DESERT_Framework/DESERT/mobility/uwsmposition/uwsmposition.h b/DESERT_Framework/DESERT/mobility/uwsmposition/uwsmposition.h index fb9d78d5..00dc1deb 100644 --- a/DESERT_Framework/DESERT/mobility/uwsmposition/uwsmposition.h +++ b/DESERT_Framework/DESERT/mobility/uwsmposition/uwsmposition.h @@ -140,10 +140,6 @@ class UWSMPosition : public Position * Method that updates both the position coordinates */ virtual void update(double now); - - -private: - double trgTime_; /// time in which the TCL command setdest is invoked double lastUpdateTime_; /// time last updated of the coordinates was /// computed @@ -158,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/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl index 25c105ff..1c0ba1be 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl @@ -127,7 +127,7 @@ $ns use-Miracle ################## set opt(n_auv) 2 ;# Number of Nodes set opt(starttime) 1 -set opt(stoptime) 6000 +set opt(stoptime) 15000 set opt(txduration) [expr $opt(stoptime) - $opt(starttime)] set opt(rngstream) 1 @@ -193,7 +193,7 @@ if {$opt(bash_parameters)} { } } -set opt(waypoint_file) "../dbs/wp_path/rov_path_simple.csv" +set opt(waypoint_file) "../dbs/wp_path/rov_path.csv" #random generator global defaultRNG From 62a944147f4257fe8c5b99ef028fd0584a364055 Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Fri, 23 Jun 2023 08:56:11 +0200 Subject: [PATCH 10/36] added control validity pkt rcv --- DESERT_Addons/uwauv/uwauv-packet.h | 4 + DESERT_Addons/uwauv/uwauvctrer-module.cc | 268 ++++++++++++++--------- DESERT_Addons/uwauv/uwauvctrer-module.h | 17 +- DESERT_Addons/uwauv/uwauverror-module.cc | 118 ++++++---- DESERT_Addons/uwauv/uwauverror-module.h | 8 +- 5 files changed, 250 insertions(+), 165 deletions(-) diff --git a/DESERT_Addons/uwauv/uwauv-packet.h b/DESERT_Addons/uwauv/uwauv-packet.h index 645ef871..7985e170 100644 --- a/DESERT_Addons/uwauv/uwauv-packet.h +++ b/DESERT_Addons/uwauv/uwauv-packet.h @@ -135,6 +135,7 @@ typedef struct hdr_uwAUV_error { 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. */ @@ -171,4 +172,7 @@ typedef struct hdr_uwAUV_error { inline float& speed() { return speed_; } + inline float& error() { + return error_; + } } hdr_uwAUV_error; diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.cc b/DESERT_Addons/uwauv/uwauvctrer-module.cc index 2f713438..7bf6f364 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.cc +++ b/DESERT_Addons/uwauv/uwauvctrer-module.cc @@ -78,19 +78,18 @@ UwAUVCtrErModule::UwAUVCtrErModule(UWSMEPosition* p) , ackTimeout(10) , drop_old_waypoints(1) , log_flag(0) - , pos_log(0) - //, alarm_mode(false) , period(60) + , speed(4) { posit=p; - speed=5; x_sorg = posit->getX(); y_sorg = posit->getY(); - //alarm_mode = false; + bind("ackTimeout_", (int*) &ackTimeout); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); bind("log_flag_", (int*) &log_flag ); bind("period_", (int*) &period ); + if (ackTimeout < 0) { cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" << std::endl; @@ -106,19 +105,16 @@ UwAUVCtrErModule::UwAUVCtrErModule() , ackTimeout(10) , drop_old_waypoints(1) , log_flag(0) - //, out_file_stats(0) - //, alarm_mode(false) , period(60) + , speed(4) { p = NULL; UWSMEPosition p = UWSMEPosition(); posit=&p; - x_sorg = 0; - y_sorg = 0; - //posit = Position(); - speed = 5; - //alarm_mode = false; + x_sorg = posit->getX(); + y_sorg = posit->getY(); + bind("ackTimeout_", (int*) &ackTimeout); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); bind("log_flag_", (int*) &log_flag ); @@ -171,28 +167,6 @@ int UwAUVCtrErModule::command(int argc, const char*const* argv) { return TCL_OK; } } - /*else if(argc == 4){ - /**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); } @@ -200,11 +174,15 @@ int UwAUVCtrErModule::command(int argc, const char*const* argv) { void UwAUVCtrErModule::start() {} void UwAUVCtrErModule::setPosition(UWSMEPosition* p){ + posit = p; + x_sorg = posit->getX(); + y_sorg = posit->getY(); } void UwAUVCtrErModule::transmit() { + sendPkt(); if (debug_) { @@ -217,9 +195,11 @@ void UwAUVCtrErModule::transmit() { } 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); + } void UwAUVCtrErModule::initPkt(Packet* p) { @@ -228,37 +208,73 @@ void UwAUVCtrErModule::initPkt(Packet* p) { hdr_uwcbr *uwcbrh = HDR_UWCBR(p); bool found = false; + uwAUVh->speed() = 0; uwAUVh->ack() = ack; ack = 0; if(this->p == NULL){ //TO FIX - if ((abs(posit->getX() - x_auv) < 1) && (abs(posit->getY() - y_auv ) < 1) && alarm_mode){ //If in the right position + if ((getDistance(posit->getX(),posit->getY(),x_auv,y_auv) == 0.0) && alarm_mode){ //If in the right position found = true; - } - //if((getDistance(x_sorg,y_sorg,x_auv,y_auv) < getDistance(posit->getX(),posit->getY(),x_auv,y_auv)) && alarm_mode){ //if the right position - // // has been already passed - // found = true; - //} + if (debug_) { + std::cout << NOW << " UwAUVCtrErrModule::recv(Packet *p) SV reached the destination"<< std::endl; + } + }else if((getDistance(x_sorg,y_sorg,x_auv,y_auv) < getDistance(posit->getX(),posit->getY(),x_sorg,y_sorg)) && alarm_mode){ //if the right position // has been already passed + found = true; + if (debug_) { + std::cout << NOW << " UwAUVCtrErrModule::recv(Packet *p) SV have gone too far "<< std::endl; + } + + } if (found){ - uwAUVh->speed() = 100; + uwAUVh->speed() = -1; alarm_mode = false; uwAUVh->sn() = ++sn; + uwAUVh->x() = x_auv; + uwAUVh->y() = y_auv; this->p = p; - if (debug_) { - std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) ERROR SOLVED" - << std::endl; - } - if (log_flag == 1) { + err_log.open("error_log.csv",std::ios_base::app); err_log << NOW << "," << x_auv<<","<getX() << ","<< posit->getY() + << ","<< posit->getZ() << std::endl; + pos_log.close(); + + } + + + if (! alarm_queue.empty()){ //take care of the next error + + x_auv = alarm_queue[0][0]; + y_auv = alarm_queue[0][1]; + + posit->setdest(x_auv,y_auv,posit->getZ(),speed); + alarm_mode = true; + + alarm_queue.erase(alarm_queue.begin()); + + x_sorg = posit->getX(); + y_sorg = posit->getY(); + + if (debug_) { + std::cout << NOW << " UwAUVCtrErrModule::recv(Packet *p) SV picked a new " + "error from the queue: X = " << x_auv << ", Y = " << y_auv<< std::endl; + } + + } + + if (debug_) { + std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) ERROR ("<< x_auv << "," << y_auv << ") SOLVED" + << std::endl; } } @@ -270,32 +286,43 @@ void UwAUVCtrErModule::initPkt(Packet* p) { //Retransmission }else{ - - if ((abs(posit->getX() - x_auv) < 1) && (abs(posit->getY() - y_auv ) < 1) && alarm_mode){ //If in the right position - found = true; + + uwAUVh->speed() = -1; + alarm_mode = false; + uwAUVh->sn() = sn; + uwAUVh->x() = x_auv; + uwAUVh->y() = y_auv; + + + if (log_flag == 1) { + + pos_log.open("position_log.csv",std::ios_base::app); + pos_log << NOW << "," << posit->getX() << ","<< posit->getY() + << ","<< posit->getZ() << std::endl; + pos_log.close(); + } - //if((getDistance(x_sorg,y_sorg,x_auv,y_auv) < getDistance(posit->getX(),posit->getY(),x_auv,y_auv)) && alarm_mode){ //if the right position - // // has been already passed - // found = true; - //} - - if (found){ - uwAUVh->speed() = 100; - alarm_mode = false; - uwAUVh->sn() = sn; + if (debug_) { + std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) Retransmission ERROR ERROR ("<< x_auv << "," << y_auv << ") SOLVED" + << std::endl; + } + + if (! alarm_queue.empty()){ + x_auv = alarm_queue[0][0]; + y_auv = alarm_queue[0][1]; + posit->setdest(x_auv,y_auv,posit->getZ(),speed); + alarm_mode = true; + x_sorg = posit->getX(); + y_sorg = posit->getY(); + alarm_queue.erase(alarm_queue.begin()); if (debug_) { - std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) Retransmission ERROR SOLVED" - << std::endl; + std::cout << NOW << " UwAUVCtrErrModule::recv(Packet *p) SV picked a new " + "error from the queue: X = " << x_auv << ", Y = " << y_auv<< std::endl; } - - if (log_flag == 1) { - err_log.open("error_log.csv",std::ios_base::app); - err_log << NOW << "," << x_auv<<","<getX() << ","<< posit->getY() - << ","<< posit->getZ() << std::endl; - pos_log.close(); + pos_log.open("position_log.csv",std::ios_base::app); + pos_log << NOW << "," << posit->getX() << ","<< posit->getY() + << ","<< posit->getZ() << std::endl; + pos_log.close(); } - x_sorg = posit->getX(); - y_sorg = posit->getY(); } void UwAUVCtrErModule::recv(Packet* p, Handler* h) { @@ -328,7 +353,6 @@ void UwAUVCtrErModule::recv(Packet* p) { if(uwAUVh->ack() == sn + 1) { //ack received - //sendTmr_.force_cancel(); this->p = NULL; } @@ -340,55 +364,85 @@ void UwAUVCtrErModule::recv(Packet* p) { std::cout << NOW << " UwAUVErrorModule::recv(Packet *p) error NACK " <<"received"<< std::endl; - if (!alarm_mode){ + - if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { //obsolete packets - if (debug_) { - std::cout << NOW << " UwAUVCtrErrModule::old error with sn " - << uwAUVh->sn() << " dropped " << std::endl; - } + if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { //obsolete packets + if (debug_) { + std::cout << NOW << " UwAUVCtrErrModule::old error with sn " + << uwAUVh->sn() << " dropped " << std::endl; + } - } else { //packet in order - x_auv = uwAUVh->x(); - y_auv = uwAUVh->y(); - posit->setdest(x_auv,y_auv,posit->getZ(),1); - last_sn_confirmed = uwAUVh->sn(); - alarm_mode = true; - x_sorg = posit->getX(); - y_sorg = posit->getY(); + } else { + if (uwAUVh->error() == 5){//packet in order - } + if (!alarm_mode){// TO CLEAN - ack = last_sn_confirmed+1; + if (alarm_queue.empty()){ - if (log_flag == 1) { - pos_log.open("position_log.csv",std::ios_base::app); - pos_log<< NOW << ","<getX() << ","<< posit->getY() - << ","<< posit->getZ() << std::endl; - pos_log.close(); - } + x_auv = uwAUVh->x(); + y_auv = uwAUVh->y(); + posit->setdest(x_auv,y_auv,posit->getZ(),speed); - if (debug_) { - std::cout << NOW << " UwAUVCtrErrModule::recv(Packet *p) SV received new " - "error: X = " << uwAUVh->x() << ", Y = " << uwAUVh->y() - << ", Z = " << uwAUVh->z() << " speed "<< uwAUVh->speed()<< std::endl; - } + last_sn_confirmed = uwAUVh->sn(); + alarm_mode = true; - UwCbrModule::recv(p); + x_sorg = posit->getX(); + y_sorg = posit->getY(); + if (debug_) { + std::cout << NOW << " UwAUVCtrErrModule::recv(Packet *p) SV received new " + "error: X = " << uwAUVh->x() << ", Y = " << uwAUVh->y() + << ", Z = " << uwAUVh->z() << " speed "<< uwAUVh->speed()<< std::endl; + } - if (debug_) - cout << NOW << " ACK sent immediately with standard priority " - << std::endl; + }else{ + + x_auv = alarm_queue[0][0]; + y_auv = alarm_queue[0][1]; + posit->setdest(x_auv,y_auv,posit->getZ(),speed); + + alarm_mode = true; + + last_sn_confirmed = uwAUVh->sn(); + + x_sorg = posit->getX(); + y_sorg = posit->getY(); + alarm_queue.erase(alarm_queue.begin()); + alarm_queue.push_back({uwAUVh->x(),uwAUVh->y()}); + + if (debug_) { + std::cout << NOW << " UwAUVCtrErrModule::recv(Packet *p) SV picked a new " + "error from the queue: X = " << x_auv << ", Y = " << y_auv<< std::endl; + } + + } + }else{ + + last_sn_confirmed = uwAUVh->sn(); + alarm_queue.push_back({uwAUVh->x(),uwAUVh->y()}); + + if (debug_) { + std::cout << NOW << " UwAUVCtrErrModule::recv(Packet *p) SV add new " + "error in the queue: X = " << uwAUVh->x() << ", Y = " << uwAUVh->y() << std::endl; + } + } + } } + ack = last_sn_confirmed+1; + + UwCbrModule::recv(p); UwCbrModule::sendPkt(); - if (debug_) - std::cout << NOW << " UwAUVCtrErrModule::recv(Packet *p) Packet dropped: " - << "alarm mode "<< std::endl; + if (log_flag == 1) { + pos_log.open("position_log.csv",std::ios_base::app); + pos_log<< NOW << ","<getX() << ","<< posit->getY() + << ","<< posit->getZ() << std::endl; + pos_log.close(); + } + } diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.h b/DESERT_Addons/uwauv/uwauvctrer-module.h index 96dc6940..0b4fc94d 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.h +++ b/DESERT_Addons/uwauv/uwauvctrer-module.h @@ -28,7 +28,7 @@ // /** * @file uwauvctr-module.h -* @author Filippo Campagnaro +* @author Filippo Campagnaro, Alessia Ortile * @version 1.0.0 * * \brief Provides the definition of the class UWAUV. @@ -200,23 +200,24 @@ class UwAUVCtrErModule : public UwCbrModule { int drop_old_waypoints; float x_auv; /**< X of the last AUV position with an error.*/ float y_auv; /**< Y of the last AUV position with an error.*/ - float z_auv; /**< Z of the last AUV position with an error.*/ - float speed; /**< Moving speed sent to the AUV.*/ int period; Packet* p; int log_flag; - std::ofstream pos_log; - std::ofstream err_log; int ackTimeout; - static bool alarm_mode; float x_sorg; float y_sorg; - - //bool alarm_mode; + double speed; + + static bool alarm_mode; + static vector> alarm_queue; + + std::ofstream pos_log; + std::ofstream err_log; }; bool UwAUVCtrErModule::alarm_mode = false; +vector> UwAUVCtrErModule::alarm_queue = {}; #endif // UWAUVCtr_MODULE_H diff --git a/DESERT_Addons/uwauv/uwauverror-module.cc b/DESERT_Addons/uwauv/uwauverror-module.cc index 24025138..20cbe063 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.cc +++ b/DESERT_Addons/uwauv/uwauverror-module.cc @@ -86,12 +86,12 @@ UwAUVErrorModule::UwAUVErrorModule() , ackNotPgbk(0) , drop_old_waypoints(1) , log_flag(0) - , out_file_stats(0) , period(60) , error_p(0.2) + , alarm_mode(false) + , speed(1) { UWSMEPosition p = UWSMEPosition(); - speed = 5; posit=&p; bind("ackTimeout_", (int*) &ackTimeout); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); @@ -117,12 +117,12 @@ UwAUVErrorModule::UwAUVErrorModule(UWSMEPosition* p) , ackNotPgbk(0) , drop_old_waypoints(1) , log_flag(0) - , out_file_stats(0) , period(60) - , error_p(0.2) + , error_p(0.1) + , alarm_mode(false) + , speed(1) { posit = p; - speed = 5; bind("ackTimeout_", (int*) &ackTimeout); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); bind("log_flag_", (int*) &log_flag ); @@ -242,73 +242,79 @@ void UwAUVErrorModule::initPkt(Packet* p) { uwAUVh->ack() = ack; ack = 0; - + uwAUVh->error() = 0; if(this->p == NULL){ random_device rd; mt19937 generator(rd()); uniform_real_distribution distrib(0.0, 1.0); - - double randomValue = distrib(generator) ; - if(randomValue < error_p){ - - uwAUVh->x() = posit->getX(); - uwAUVh->y() = posit->getY(); - x_e = posit->getX(); - y_e = posit->getY(); + if((randomValue < error_p) && (!alarm_mode)){ posit->setdest(posit->getXdest(),posit->getYdest(),posit->getZdest(),0); posit->setAlarm(true); + alarm_mode = true; + x_e = posit->getX(); + y_e = posit->getY(); + + uwAUVh->x() = x_e; + uwAUVh->y() = y_e; + uwAUVh->error() = 5; uwAUVh->sn() = ++sn; - this->p = p; - //TODO: stop devices when send the alarm + this->p = p; if (debug_) { std::cout << NOW << " UwAUVErroModule::initPkt(Packet *p) " - << "ERROR!"<<"(speed="<getSpeed()<<")" << std::endl; + << "ERROR ("<< x_e <<","<< y_e <<"), alarm_mode = "<< alarm_mode << std::endl; } if (log_flag == 1) { - error_log.open("error_calling_log.csv",std::ios_base::app); - error_log << NOW << "," << posit->getX()<<","<getY()<< std::endl; - error_log.close(); + err_log.open("error_calling_log.csv",std::ios_base::app); + err_log << NOW << "," << x_e <<","<< y_e << std::endl; + err_log.close(); + } + + if (log_flag == 1) { + out_file_stats.open("postion_log_a.csv",std::ios_base::app); + out_file_stats << NOW << "," << posit->getX() << ","<< posit->getY() + << "," << posit->getZ() << std::endl; + out_file_stats.close(); } } } else{ //Retransmit - - //retrasmission of the point where the error was called - uwAUVh->x() = x_e; - uwAUVh->y() = y_e; - uwAUVh->sn() = sn; + if (alarm_mode){ + //retrasmission of the point where the error was called + uwAUVh->x() = x_e; + uwAUVh->y() = y_e; + uwAUVh->sn() = sn; + uwAUVh->error() = 5; - if (debug_) { - std::cout << NOW << " UwAUVErroModule::initPkt(Packet *p) " - << "Retransmitting"<< std::endl; - } + if (debug_) { + std::cout << NOW << " UwAUVErroModule::initPkt(Packet *p) " + << "Retransmitting ERROR ("<< x_e <<","<< y_e <<")"<< std::endl; + } + } } + UwCbrModule::initPkt(p); + if (debug_){ hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); std::cout << NOW << " UwAUVErrorModule::initPkt(Packet *p) AUV current " - << "position: X = " << uwAUVh->x() << ", Y = " << uwAUVh->y() - << ", Z = " << uwAUVh->z()<< std::endl; + << "position: X = " << posit->getX() << ", Y = " << posit->getY() << std::endl; } - //ackTimer_.force_cancel(); - UwCbrModule::initPkt(p); - if (log_flag == 1) { out_file_stats.open("postion_log_a.csv",std::ios_base::app); - out_file_stats << left << NOW << "," << posit->getX() << ","<< posit->getY() + out_file_stats << NOW << "," << posit->getX() << ","<< posit->getY() << "," << posit->getZ() << std::endl; out_file_stats.close(); } @@ -328,36 +334,45 @@ void UwAUVErrorModule::recv(Packet* p) { } if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { //obsolete packets + if (debug_) { std::cout << NOW << " UwAUVErrModule::old error with sn " << uwAUVh->sn() << " dropped " << std::endl; } } else { //packet in order - //TODO: When sv reaches the right position set speed > 0 - if(uwAUVh->speed() == 100){ + + if(uwAUVh->speed() == -1 && uwAUVh->x() == x_e && uwAUVh->y() == y_e && alarm_mode){ posit->setAlarm(false); - posit->setdest(posit->getXdest(),posit->getYdest(),posit->getZdest(),1); + alarm_mode = false; + posit->setdest(posit->getXdest(),posit->getYdest(),posit->getZdest(),speed); + if (debug_) { - std::cout << NOW << " UwAUVErrModule::recv(Packet *p) error solved " + std::cout << NOW << " UwAUVErrModule::recv(Packet *p) error ("<< x_e <<","<< y_e <<") solved " "AUV can move again with speed=" << posit->getSpeed()<< std::endl; - } + } + + if (log_flag == 1) { + err_solved_log.open("error_log_a.csv",std::ios_base::app); + err_solved_log << NOW << "," << posit->getX() <<","<< posit->getY() << "," << posit->getSpeed() << std::endl; + err_solved_log.close(); + } + + if (log_flag == 1) { + out_file_stats.open("postion_log_a.csv",std::ios_base::app); + out_file_stats << NOW << "," << posit->getX() << ","<< posit->getY() + << "," << posit->getZ() << std::endl; + out_file_stats.close(); + } } + last_sn_confirmed = uwAUVh->sn(); } ack = last_sn_confirmed+1; - //to update - if (log_flag == 1) { - out_file_stats.open("postion_log_a.csv",std::ios_base::app); - out_file_stats << left << NOW << "," << posit->getX() << ","<< posit->getY() - << "," << posit->getZ() << std::endl; - out_file_stats.close(); - } - UwCbrModule::recv(p); @@ -371,4 +386,11 @@ void UwAUVErrorModule::recv(Packet* p) { std::cout << NOW << " UwAUVErrorModule::recv(Packet *p) error NACK " <<"received"<< std::endl; + if (log_flag == 1) { + out_file_stats.open("postion_log_a.csv",std::ios_base::app); + out_file_stats << NOW << "," << posit->getX() << ","<< posit->getY() + << "," << posit->getZ() << std::endl; + out_file_stats.close(); + } + } diff --git a/DESERT_Addons/uwauv/uwauverror-module.h b/DESERT_Addons/uwauv/uwauverror-module.h index 00fd9717..ec01be1a 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.h +++ b/DESERT_Addons/uwauv/uwauverror-module.h @@ -182,7 +182,6 @@ class UwAUVErrorModule : public UwCbrModule { enum UWAUV_ACK_POLICY { ACK_PIGGYBACK, ACK_IMMEDIATELY, ACK_PGBK_OR_TO }; UWSMEPosition* posit; /**< AUV position.*/ - float speed; int last_sn_confirmed;/**< Sequence number of the last command Packete received.*/ int sn; int ack; @@ -205,10 +204,15 @@ class UwAUVErrorModule : public UwCbrModule { Packet* p; int period; std::ofstream out_file_stats; /**< Output stream for the textual file of debug */ - std::ofstream error_log; + std::ofstream err_log; + std::ofstream err_solved_log; float x_e; float y_e; float error_p; + bool alarm_mode; + +private: + double speed; }; #endif // UWAUVError_MODULE_H From 63aaee5126d5f4f6784addef4c061f2eb9220bcb Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Fri, 23 Jun 2023 09:10:00 +0200 Subject: [PATCH 11/36] waypoints --- .../mobility/uwsmeposition/uwsmeposition.cpp | 253 +++++++++++------- .../mobility/uwsmeposition/uwsmeposition.h | 87 ++---- 2 files changed, 181 insertions(+), 159 deletions(-) diff --git a/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.cpp b/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.cpp index 60c53c5a..03a25c42 100644 --- a/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.cpp +++ b/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.cpp @@ -57,9 +57,10 @@ static class UWSMEPositionClass : public TclClass } } class_uwsmeposition; + UWSMEPosition::UWSMEPosition() : UWSMPosition() - , alarm_mode(0) + , alarm_mode(false) { bind("debug_", &debug_); } @@ -114,30 +115,68 @@ UWSMEPosition::command(int argc, const char *const *argv) void UWSMEPosition::setdest( - double x_dest, double y_dest, double z_dest, double spead_setted) + double x_dest, double y_dest, double z_dest, double speed_setted) { if (alarm_mode){ - UWSMPosition::setdest(x_dest,y_dest,z_dest); + if (debug_) - printf("New pos (%f,%f,%f), dest(%f,%f,%f), speed blocked by ALARM\n", - getX(), - getY(), - getZ(), - getXdest(), - getYdest(), - getZdest()); + printf("Alarm_mode %f, dest(%f,%f,%f) not accepted\n", + alarm_mode, + x_dest, + y_dest, + z_dest); }else{ - UWSMPosition::setdest(x_dest,y_dest,z_dest,spead_setted); + + UWSMPosition::setdest(x_dest,y_dest,z_dest,speed_setted); + + if (debug_) + printf("Pos (%f,%f,%f), new dest(%f,%f,%f), speed = %f\n", + x_, + y_, + z_, + Xdest_, + Ydest_, + Zdest_, + speed_setted); } } + +void +UWSMEPosition::setdest(double x_dest, double y_dest, double z_dest) +{ + if (alarm_mode){ + + if (debug_) + printf("Alarm_mode %f, dest(%f,%f,%f) not accepted\n", + alarm_mode, + x_dest, + y_dest, + z_dest); + }else{ + + UWSMPosition::setdest(x_dest,y_dest,z_dest); + + if (debug_) + printf("Pos (%f,%f,%f), new dest(%f,%f,%f)\n", + x_, + y_, + z_, + Xdest_, + Ydest_, + Zdest_); + } +} + void UWSMEPosition::adddest( double x_dest, double y_dest, double z_dest, double speed_setted) { if (!waypoints.empty()){ - waypoints.push_back({x_dest,y_dest,z_dest,speed_setted}); + + waypoints.push_back({x_dest,y_dest,z_dest, speed_setted}); + if (debug_) printf("New waypoint (%f,%f,%f)\n", x_dest, @@ -145,16 +184,61 @@ UWSMEPosition::adddest( z_dest); }else{ - setdest(x_dest,y_dest,z_dest,speed_setted); + UWSMEPosition::setdest(x_dest,y_dest,z_dest, speed_setted); + + if (debug_) + printf("Pos (%f,%f,%f), new dest(%f,%f,%f)\n", + x_, + y_, + z_, + Xdest_, + Ydest_, + Zdest_); } - -} + + /*if (!waypoints.empty()){ + + waypoints.push_back({x_dest,y_dest,z_dest,speed_setted}); + + if (debug_) + printf("New waypoint (%f,%f,%f)\n", + x_dest, + y_dest, + z_dest); + + }else{ + + printf("trg time %f", trgTime_); + printf("dest %f %f %f", Xdest_, Ydest_, Zdest_); + printf("sorg %f %f %f", Xsorg_, Ysorg_, Zsorg_); + printf("now %f %f %f", x_, y_, z_); + + waypoints.push_back({x_dest,y_dest,z_dest,speed_setted}); + + if (debug_) + printf("New waypoint (%f,%f,%f)\n", + x_dest, + y_dest, + z_dest); + + double now = Scheduler::instance().clock(); + update(now); + + + + }*/ + + +} + void UWSMEPosition::adddest( double x_dest, double y_dest, double z_dest) { + if (!waypoints.empty()){ + waypoints.push_back({x_dest,y_dest,z_dest}); if (debug_) @@ -164,23 +248,52 @@ UWSMEPosition::adddest( z_dest); }else{ - setdest(x_dest,y_dest,z_dest); + UWSMEPosition::setdest(x_dest,y_dest,z_dest); + + if (debug_) + printf("Pos (%f,%f,%f), new dest(%f,%f,%f)\n", + x_, + y_, + z_, + Xdest_, + Ydest_, + Zdest_); } - - -} -void -UWSMEPosition::setdest(double x_dest, double y_dest, double z_dest) -{ - UWSMPosition::setdest(x_dest,y_dest,z_dest); + /*if (!waypoints.empty()){ + + waypoints.push_back({x_dest,y_dest,z_dest}); + + if (debug_) + printf("New waypoint (%f,%f,%f)\n", + x_dest, + y_dest, + z_dest); + + }else{ + + printf("trg time %f", trgTime_); + printf("dest %f %f %f", Xdest_, Ydest_, Zdest_); + printf("sorg %f %f %f", Xsorg_, Ysorg_, Zsorg_); + printf("now %f %f %f", x_, y_, z_); + + waypoints.push_back({x_dest,y_dest,z_dest}); + + if (debug_) + printf("New waypoint (%f,%f,%f)\n", + x_dest, + y_dest, + z_dest); + + double now = Scheduler::instance().clock(); + update(now); + }*/ + } void UWSMEPosition::update(double now) { - //UWSMPosition::update(now); - if ((trgTime_ < 0.) || (now < lastUpdateTime_ + 1e-6)) return; @@ -190,18 +303,21 @@ UWSMEPosition::update(double now) 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].size()>3){ - setdest(waypoints[0][0],waypoints[0][1],waypoints[0][2],waypoints[0][3]); + UWSMEPosition::setdest(waypoints[0][0],waypoints[0][1],waypoints[0][2],waypoints[0][3]); }else{ - setdest(waypoints[0][0],waypoints[0][1],waypoints[0][2]); + UWSMEPosition::setdest(waypoints[0][0],waypoints[0][1],waypoints[0][2]); } waypoints.erase(waypoints.begin()); + if (debug_) printf("New dest (%f,%f,%f) from waypoints list\n", Xdest_, @@ -213,15 +329,16 @@ UWSMEPosition::update(double now) theta = acos((Zdest_ - Zsorg_) / theta_den); - if (Xdest_ - Xsorg_ == 0) + 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); @@ -230,18 +347,24 @@ UWSMEPosition::update(double now) pow(Zdest_ - Zsorg_, 2.0) < pow(x_ - Xsorg_, 2.0) + pow(y_ - Ysorg_, 2.0) + pow(z_ - Zsorg_, 2.0)) { + x_ = Xdest_; y_ = Ydest_; z_ = Zdest_; if (!waypoints.empty()){ + if(waypoints[0].size()>3){ - setdest(waypoints[0][0],waypoints[0][1],waypoints[0][2],waypoints[0][3]); + + UWSMEPosition::setdest(waypoints[0][0],waypoints[0][1],waypoints[0][2],waypoints[0][3]); + }else{ - setdest(waypoints[0][0],waypoints[0][1],waypoints[0][2]); + + UWSMEPosition::setdest(waypoints[0][0],waypoints[0][1],waypoints[0][2]); } waypoints.erase(waypoints.begin()); + if (debug_) printf("New dest (%f,%f,%f) from waypoints list\n", Xdest_, @@ -268,74 +391,6 @@ UWSMEPosition::update(double now) lastUpdateTime_ = now; } -/* -double -UWSMEPosition::getX() -{ - double now = Scheduler::instance().clock(); - if ((trgTime_ > 0.) && (now > lastUpdateTime_ + 1e-6)) - update(now); - return (x_); -} - -void -UWSMEPosition::setX(double x) -{ - x_ = x; - Xdest_ = x; - Xsorg_ = x; -} -void -UWSMEPosition::setY(double y) -{ - y_ = y; - Ydest_ = y; - Ysorg_ = y; -} -void -UWSMEPosition::setZ(double z) -{ - z_ = z; - Zdest_ = z; - Zsorg_ = z; -} -double -UWSMEPosition::getY() -{ - double now = Scheduler::instance().clock(); - if ((trgTime_ > 0.) && (now > lastUpdateTime_ + 1e-6)) - update(now); - return (y_); -} - -double -UWSMEPosition::getZ() -{ - double now = Scheduler::instance().clock(); - if ((trgTime_ > 0.) && (now > lastUpdateTime_ + 1e-6)) - update(now); - return (z_); -} - -double UWSMEPosition::getXdest() const -{ - return Xdest_; -} - -double UWSMEPosition::getYdest() const -{ - return Ydest_; -} - -double UWSMEPosition::getZdest() const -{ - return Zdest_; -} - -double UWSMEPosition::getSpeed() const -{ - return speed_; -}*/ void UWSMEPosition::setAlarm(bool alarm) diff --git a/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.h b/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.h index f843133a..2d81b720 100644 --- a/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.h +++ b/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.h @@ -56,6 +56,23 @@ #define sgn(x) (((x) == 0.0) ? 0.0 : ((x) / fabs(x))) #define pi (4 * atan(1.0)) +class UWSMEPosition; + +/** +* UwSendTimer class is used to handle the scheduling period of UWAUV packets. +*/ +/*class UwDstReachedTimer : public TimerHandler +{ +public: + UwDstReachedTimer(UWSMEPosition *m) : TimerHandler() { + module = m; + } +protected: + virtual void expire(Event *e); + UWSMEPosition *module; +};*/ + + class UWSMEPosition : public UWSMPosition { public: @@ -68,44 +85,7 @@ class UWSMEPosition : public UWSMPosition */ virtual ~UWSMEPosition(); /** - * Method that return the current projection of the node on the x-axis. - * If it's necessary (updating time ia expired), update the position values - * before returns it. - */ - //virtual double getX(); - /** - * Method that return the current projection of the node on the y-axis. - * If it's necessary (updating time ia expired), update the position values - * before returns it. - */ -// virtual double getY(); - - /** - * Method that return the current projection of the node on the z-axis. - * If it's necessary (updating time ia expired), update the position values - * before returns it. - */ - //virtual double getZ(); - - /** - * Method that return the x cooridnate of the destination point. - */ - //virtual double getXdest() const; - - /** - * Method that return the y cooridnate of the destination point. - */ - //virtual double getYdest() const; - - /** - * Method that return the z cooridnate of the destination point. - */ - //virtual double getZdest() const; - - /** - * Method that return the actual speed. - */ - //double getSpeed() const; + /** * TCL command interpreter @@ -129,18 +109,20 @@ class UWSMEPosition : public UWSMPosition * **/ virtual int command(int argc, const char *const *argv); + virtual void setdest( double x_dest, double y_dest, double z_dest, double spead); + virtual void adddest( double x_dest, double y_dest, double z_dest, double spead); + virtual void setdest(double x_dest, double y_dest, double z_dest); + virtual void adddest(double x_dest, double y_dest, double z_dest); - /* - virtual void setX(double x); - virtual void setY(double y); - virtual void setZ(double z);*/ + virtual void setAlarm(bool alarm); + protected: /** * Method that updates both the position coordinates @@ -149,25 +131,10 @@ class UWSMEPosition : public UWSMPosition private: - - /*double trgTime_; /// time in which the TCL command setdest is invoked - double lastUpdateTime_; /// time last updated of the coordinates was - /// computed - double Xdest_; /// position on the x-axis of the destination point - double Ydest_; /// position on the y-axis of the destination point - double Zdest_; /// position on the z-axis of the destination point - double Xsorg_; /// position on the x-axis of the starting point (when the - /// TCL command setdest is invoked) - double Ysorg_; /// position on the y-axis of the starting point (when the - /// TCL command setdest is invoked) - double Zsorg_; /// position on the z-axis of the starting point (when the - /// TCL command setdest is invoked) - double speed_; /// speed of the node - */ - std::vector> waypoints; + std::vector> waypoints; int debug_; - - bool alarm_mode; + bool alarm_mode; //alarm_mode true block all the application from updating the destination }; + #endif From fd3ae9a838decdae1a17c0997b676a29a9b0bf10 Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Tue, 27 Jun 2023 18:23:00 +0200 Subject: [PATCH 12/36] noisy error management --- DESERT_Addons/uwauv/uwauvctrer-module.cc | 319 ++++++++++++------ DESERT_Addons/uwauv/uwauvctrer-module.h | 28 +- DESERT_Addons/uwauv/uwauverror-module.cc | 191 ++++++++--- DESERT_Addons/uwauv/uwauverror-module.h | 11 +- .../mobility/uwsmeposition/uwsmeposition.cpp | 2 +- .../DESERT/samples/desert_samples/AUV/asv.tcl | 6 +- .../DESERT/samples/desert_samples/AUV/auv.tcl | 17 +- .../desert_samples/AUV/plot_coordinates.py | 18 +- .../AUV/test_uwmulti_traffic_auv.tcl | 59 ++-- 9 files changed, 449 insertions(+), 202 deletions(-) diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.cc b/DESERT_Addons/uwauv/uwauvctrer-module.cc index 7bf6f364..ba97cceb 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.cc +++ b/DESERT_Addons/uwauv/uwauvctrer-module.cc @@ -89,6 +89,8 @@ UwAUVCtrErModule::UwAUVCtrErModule(UWSMEPosition* p) bind("drop_old_waypoints_", (int*) &drop_old_waypoints); bind("log_flag_", (int*) &log_flag ); bind("period_", (int*) &period ); + bind("sigma_", (double*) &sigma); + bind("th_ne_", (double*) &th_ne ); if (ackTimeout < 0) { cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" @@ -119,6 +121,9 @@ UwAUVCtrErModule::UwAUVCtrErModule() bind("drop_old_waypoints_", (int*) &drop_old_waypoints); bind("log_flag_", (int*) &log_flag ); bind("period_", (int*) &period ); + bind("sigma_", (double*) &sigma); + bind("th_ne_", (double*) &th_ne ); + if (ackTimeout < 0) { cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" << std::endl; @@ -211,73 +216,110 @@ void UwAUVCtrErModule::initPkt(Packet* p) { uwAUVh->speed() = 0; uwAUVh->ack() = ack; ack = 0; + uwAUVh->error() = 0; if(this->p == NULL){ //TO FIX - if ((getDistance(posit->getX(),posit->getY(),x_auv,y_auv) == 0.0) && alarm_mode){ //If in the right position - found = true; - if (debug_) { - std::cout << NOW << " UwAUVCtrErrModule::recv(Packet *p) SV reached the destination"<< std::endl; - } - - }else if((getDistance(x_sorg,y_sorg,x_auv,y_auv) < getDistance(posit->getX(),posit->getY(),x_sorg,y_sorg)) && alarm_mode){ //if the right position // has been already passed - found = true; - if (debug_) { - std::cout << NOW << " UwAUVCtrErrModule::recv(Packet *p) SV have gone too far "<< std::endl; - } + if (error_released){ - } - - if (found){ - - uwAUVh->speed() = -1; - alarm_mode = false; + uwAUVh->error() = -1; uwAUVh->sn() = ++sn; - uwAUVh->x() = x_auv; - uwAUVh->y() = y_auv; + uwAUVh->x() = x_s; + uwAUVh->y() = y_s; + error_released = false; this->p = p; - if (log_flag == 1) { + if (debug_) + std::cout << NOW << " UwAUVCtrErrModule::initPkt(Packet *p) Error released"<< std::endl; - err_log.open("error_log.csv",std::ios_base::app); - err_log << NOW << "," << x_auv<<","<getX() << ","<< posit->getY() - << ","<< posit->getZ() << std::endl; - pos_log.close(); + }else if (alarm_mode == 2){ //I need to go there + + if ((getDistance(posit->getX(),posit->getY(),x_err,y_err) == 0.0)){ //If in the right position + + found = true; + x_s = x_err; + y_s = y_err; + + if (debug_) + std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p) SV reached the destination"<< std::endl; + + + }else if((getDistance(x_sorg,y_sorg,x_err,y_err) < getDistance(posit->getX(),posit->getY(),x_sorg,y_sorg))){ //if the right position // has been already passed + + found = true; + x_s = x_err; + y_s = y_err; - } + if (debug_) + std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p) SV have gone too far "<< std::endl; + + } - if (! alarm_queue.empty()){ //take care of the next error + if (found){ + + uwAUVh->error() = -1; + alarm_mode = 0; + uwAUVh->sn() = ++sn; + uwAUVh->x() = x_s; + uwAUVh->y() = y_s; + this->p = p; - x_auv = alarm_queue[0][0]; - y_auv = alarm_queue[0][1]; + if (log_flag == 1) { - posit->setdest(x_auv,y_auv,posit->getZ(),speed); - alarm_mode = true; + err_log.open("error_log.csv",std::ios_base::app); + err_log << NOW << "," << x_s<<","<getX(); - y_sorg = posit->getY(); - if (debug_) { - std::cout << NOW << " UwAUVCtrErrModule::recv(Packet *p) SV picked a new " - "error from the queue: X = " << x_auv << ", Y = " << y_auv<< std::endl; + std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) ERROR ("<< x_err << "," << y_err << ") SOLVED" + << std::endl; } - } + /* TO DO */ + /* CHECK ALL THE STATE OF THE ERROR IN THE QUEUE, IF ONE OF THEM IS 2 THEN GO THERE*/ + + if (!alarm_queue.empty()){ //take care of the next error + + x_err = alarm_queue[0][0]; + y_err = alarm_queue[0][1]; + + posit->setdest(x_err,y_err,posit->getZ(),speed); + alarm_mode = 2; + + alarm_queue.erase(alarm_queue.begin()); + + x_sorg = posit->getX(); + y_sorg = posit->getY(); + + if (debug_) { + std::cout << NOW << " UwAUVCtrErrModule::initPkt(Packet *p) SV picked a new " + "error from the queue: X = " << x_err << ", Y = " << y_err<< std::endl; + } + + } + + }else{ + + 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 (debug_) { - std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) ERROR ("<< x_auv << "," << y_auv << ") SOLVED" - << std::endl; } } + if (debug_) { std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) ACK recv" @@ -287,42 +329,16 @@ void UwAUVCtrErModule::initPkt(Packet* p) { //Retransmission }else{ - uwAUVh->speed() = -1; - alarm_mode = false; + uwAUVh->error() = -1; uwAUVh->sn() = sn; - uwAUVh->x() = x_auv; - uwAUVh->y() = y_auv; + uwAUVh->x() = x_s; + uwAUVh->y() = y_s; - if (log_flag == 1) { - - pos_log.open("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 << " UwAUVCtrErModule::initPkt(Packet *p) Retransmission ERROR ERROR ("<< x_auv << "," << y_auv << ") SOLVED" + std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) Retransmission ERROR ("<< x_s << "," << y_s << ") solved" << std::endl; } - - if (! alarm_queue.empty()){ - x_auv = alarm_queue[0][0]; - y_auv = alarm_queue[0][1]; - posit->setdest(x_auv,y_auv,posit->getZ(),speed); - alarm_mode = true; - x_sorg = posit->getX(); - y_sorg = posit->getY(); - alarm_queue.erase(alarm_queue.begin()); - - if (debug_) { - std::cout << NOW << " UwAUVCtrErrModule::recv(Packet *p) SV picked a new " - "error from the queue: X = " << x_auv << ", Y = " << y_auv<< std::endl; - } - } - } UwCbrModule::initPkt(p); @@ -373,61 +389,128 @@ void UwAUVCtrErModule::recv(Packet* p) { } } else { - if (uwAUVh->error() == 5){//packet in order - if (!alarm_mode){// TO CLEAN + if (uwAUVh->error() == 0){// AUV MARKED IT AS NO ERROR - if (alarm_queue.empty()){ + if (debug_) + std::cout << NOW << " UwAUVCtrErrModule:: no error" << std::endl; - x_auv = uwAUVh->x(); - y_auv = uwAUVh->y(); + }else{ // error of some kind - posit->setdest(x_auv,y_auv,posit->getZ(),speed); + int status = checkError(uwAUVh->error(),1); + bool exists = false; - last_sn_confirmed = uwAUVh->sn(); - alarm_mode = true; + if (!gray_queue.empty()){ + + int i = 0; + // Itera su ciascun vettore interno di gray_queue + for (const auto& vec : gray_queue) { + // Controlla se le coordinate corrispondono + if (vec[0] == uwAUVh->x() && vec[1] == uwAUVh->y()) { + exists = true; + break; + } - x_sorg = posit->getX(); - y_sorg = posit->getY(); + i++; + } - if (debug_) { - std::cout << NOW << " UwAUVCtrErrModule::recv(Packet *p) SV received new " - "error: X = " << uwAUVh->x() << ", Y = " << uwAUVh->y() - << ", Z = " << uwAUVh->z() << " speed "<< uwAUVh->speed()<< std::endl; - } + if(exists){ - }else{ + if (debug_) + std::cout << NOW << " UwAUVCtrErrModule::recv(Pakct p) gray_queue error value updated, old error("<< gray_queue[i][2] << "),"; - x_auv = alarm_queue[0][0]; - y_auv = alarm_queue[0][1]; - posit->setdest(x_auv,y_auv,posit->getZ(),speed); + gray_queue[i][2] += uwAUVh->error(); + gray_queue[i][3] += 1; - alarm_mode = true; + status = checkError(gray_queue[i][2],gray_queue[i][3]); + + if (debug_) + std::cout << " updated error("<< gray_queue[i][2] << ")" << std::endl; - last_sn_confirmed = uwAUVh->sn(); - x_sorg = posit->getX(); - y_sorg = posit->getY(); - alarm_queue.erase(alarm_queue.begin()); - alarm_queue.push_back({uwAUVh->x(),uwAUVh->y()}); + } + } + + 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] << std::endl; + + + } + + + } else if(status == 2){ //status 2 + + //delete point in gray_queue + + 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->setdest(x_err,y_err,posit->getZ(),speed); + + alarm_mode = status; + + 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; + }else{ + + x_err = alarm_queue[0][0]; + y_err = alarm_queue[0][1]; + posit->setdest(x_err,y_err,posit->getZ(),speed); + + alarm_mode = status; + + x_sorg = posit->getX(); + y_sorg = posit->getY(); + + alarm_queue.erase(alarm_queue.begin()); + 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; - if (debug_) { - std::cout << NOW << " UwAUVCtrErrModule::recv(Packet *p) SV picked a new " - "error from the queue: X = " << x_auv << ", Y = " << y_auv<< std::endl; } + }else{ + + 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; + + } + }else{ - last_sn_confirmed = uwAUVh->sn(); - alarm_queue.push_back({uwAUVh->x(),uwAUVh->y()}); - if (debug_) { - std::cout << NOW << " UwAUVCtrErrModule::recv(Packet *p) SV add new " - "error in the queue: X = " << uwAUVh->x() << ", Y = " << uwAUVh->y() << std::endl; - } + //delete point in gray_queue + error_released = true; + x_s = uwAUVh->x(); + y_s = uwAUVh->y(); + if (debug_) + std::cout << NOW << " UwAUVCtrErrModule:: After some tx converged to no error" << std::endl; } + } + + last_sn_confirmed = uwAUVh->sn(); } ack = last_sn_confirmed+1; @@ -446,3 +529,25 @@ void UwAUVCtrErModule::recv(Packet* p) { } +int UwAUVCtrErModule::checkError(double m, int n_pkt){ + + // Calculate the probability using std::erfc + double p_e = std::erfc(((th_ne - (m/n_pkt)) * std::sqrt(n_pkt) / std::sqrt(2.0)) / sigma); // prob of true error (t_e) greater than th_ne + //double th_5sig = std::erfc((5*sigma) / std::sqrt(2)) / 2; + + int status; + + if (p_e <= 0.001){ //if p_e is small enough --> no error + // NO ERROR + status = 0; + }else if (p_e >= (1-0.001)){ + // FOR SURE ERROR + status = 2; + }else{ + //I NEED MORE DATA + status = 1; + } + + return status; +} + diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.h b/DESERT_Addons/uwauv/uwauvctrer-module.h index 0b4fc94d..69db2bc9 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.h +++ b/DESERT_Addons/uwauv/uwauvctrer-module.h @@ -198,9 +198,13 @@ class UwAUVCtrErModule : public UwCbrModule { int sn; /**Sequence number of the last control packet sent.*/ int ack; int drop_old_waypoints; - float x_auv; /**< X of the last AUV position with an error.*/ - float y_auv; /**< Y of the last AUV position with an error.*/ 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; int log_flag; @@ -209,15 +213,29 @@ class UwAUVCtrErModule : public UwCbrModule { float y_sorg; double speed; - static bool alarm_mode; + static int alarm_mode; + bool error_released; /* + * 0 no error + * 1 maybe an error --> wait more info + * 2 for sure an error -> go there + */ static vector> alarm_queue; + static vector> gray_queue; + +private: + + virtual int checkError(double m, int n_pkt); std::ofstream pos_log; - std::ofstream err_log; + std::ofstream err_log; + double sigma; // standard deviation + double th_ne; // if x < th_e NO error + }; -bool UwAUVCtrErModule::alarm_mode = false; +int UwAUVCtrErModule::alarm_mode = 0; vector> UwAUVCtrErModule::alarm_queue = {}; +vector> UwAUVCtrErModule::gray_queue = {}; #endif // UWAUVCtr_MODULE_H diff --git a/DESERT_Addons/uwauv/uwauverror-module.cc b/DESERT_Addons/uwauv/uwauverror-module.cc index 20cbe063..7b502650 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.cc +++ b/DESERT_Addons/uwauv/uwauverror-module.cc @@ -87,8 +87,8 @@ UwAUVErrorModule::UwAUVErrorModule() , drop_old_waypoints(1) , log_flag(0) , period(60) - , error_p(0.2) - , alarm_mode(false) + , error_p(0) + , alarm_mode(0) , speed(1) { UWSMEPosition p = UWSMEPosition(); @@ -97,7 +97,8 @@ UwAUVErrorModule::UwAUVErrorModule() bind("drop_old_waypoints_", (int*) &drop_old_waypoints); bind("log_flag_", (int*) &log_flag ); bind("period_", (int*) &period ); - bind("error_p_", (int*) &error_p ); + bind("sigma_", (double*) &sigma ); + bind("th_ne_", (double*) &th_ne ); if (ackTimeout < 0) { cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" << std::endl; @@ -118,8 +119,8 @@ UwAUVErrorModule::UwAUVErrorModule(UWSMEPosition* p) , drop_old_waypoints(1) , log_flag(0) , period(60) - , error_p(0.1) - , alarm_mode(false) + , error_p(0) + , alarm_mode(0) , speed(1) { posit = p; @@ -127,7 +128,9 @@ UwAUVErrorModule::UwAUVErrorModule(UWSMEPosition* p) bind("drop_old_waypoints_", (int*) &drop_old_waypoints); bind("log_flag_", (int*) &log_flag ); bind("period_", (int*) &period ); - bind("error_p_", (int*) &error_p ); + bind("sigma_", (double*) &sigma); + bind("th_ne_", (double*) &th_ne ); + if (ackTimeout < 0) { cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" << std::endl; @@ -244,38 +247,42 @@ void UwAUVErrorModule::initPkt(Packet* p) { ack = 0; uwAUVh->error() = 0; - if(this->p == NULL){ + if (alarm_mode != 2 ){ - random_device rd; - mt19937 generator(rd()); - uniform_real_distribution distrib(0.0, 1.0); - double randomValue = distrib(generator) ; + if (alarm_mode == 1){ - if((randomValue < error_p) && (!alarm_mode)){ + error_p = getErrorProb(t_e); + + }else{ + + error_p = getErrorProb(); + } - posit->setdest(posit->getXdest(),posit->getYdest(),posit->getZdest(),0); + + + if (alarm_mode == 1){ + + posit->setdest(posit->getXdest(),posit->getYdest(),posit->getZdest(),0); //STOP posit->setAlarm(true); - alarm_mode = true; + //alarm_mode = true; - x_e = posit->getX(); + x_e = posit->getX(); // Save error position y_e = posit->getY(); - uwAUVh->x() = x_e; + uwAUVh->x() = x_e; uwAUVh->y() = y_e; - uwAUVh->error() = 5; - uwAUVh->sn() = ++sn; - + uwAUVh->error() = error_p; this->p = p; if (debug_) { std::cout << NOW << " UwAUVErroModule::initPkt(Packet *p) " - << "ERROR ("<< x_e <<","<< y_e <<"), alarm_mode = "<< alarm_mode << std::endl; + << "ERROR ("<< x_e <<","<< y_e << "," << error_p <<"), alarm_mode = "<< alarm_mode<<", true error= "<< t_e << std::endl; } if (log_flag == 1) { err_log.open("error_calling_log.csv",std::ios_base::app); - err_log << NOW << "," << x_e <<","<< y_e << std::endl; + err_log << NOW << "," << x_e <<","<< y_e << "," << posit->getZ() << "," << error_p << std::endl; err_log.close(); } @@ -286,24 +293,18 @@ void UwAUVErrorModule::initPkt(Packet* p) { out_file_stats.close(); } - } - } - else{ //Retransmit - - if (alarm_mode){ - //retrasmission of the point where the error was called - uwAUVh->x() = x_e; - uwAUVh->y() = y_e; - uwAUVh->sn() = sn; - uwAUVh->error() = 5; + }else{ if (debug_) { - std::cout << NOW << " UwAUVErroModule::initPkt(Packet *p) " - << "Retransmitting ERROR ("<< x_e <<","<< y_e <<")"<< std::endl; + std::cout << NOW << " UwAUVErroModule::initPkt(Packet *p) " + << "no error "<<" alarm_mode = " << alarm_mode << std::endl; } - } + + } } + uwAUVh->sn() = ++sn; + UwCbrModule::initPkt(p); if (debug_){ @@ -342,10 +343,18 @@ void UwAUVErrorModule::recv(Packet* p) { } else { //packet in order - if(uwAUVh->speed() == -1 && uwAUVh->x() == x_e && uwAUVh->y() == y_e && alarm_mode){ + /** + * error > 0 tx more data + * error > 1 stop tx, Ctr is coming + * error < 0 stop tx, there is no error + */ + + if (alarm_mode && uwAUVh->x() == x_e && uwAUVh->y() == y_e){ //Valid pkt refering to my error + + if (uwAUVh->error() < 0 ){ posit->setAlarm(false); - alarm_mode = false; + alarm_mode = 0; posit->setdest(posit->getXdest(),posit->getYdest(),posit->getZdest(),speed); @@ -360,13 +369,24 @@ void UwAUVErrorModule::recv(Packet* p) { err_solved_log.close(); } - if (log_flag == 1) { - out_file_stats.open("postion_log_a.csv",std::ios_base::app); - out_file_stats << NOW << "," << posit->getX() << ","<< posit->getY() - << "," << posit->getZ() << std::endl; - out_file_stats.close(); - } + } else if (uwAUVh->error() >= 1 ){ + + alarm_mode = 2; + + if (debug_) + std::cout << NOW << " UwAUVErrModule::recv(Packet *p) for SURE there is an error ("<< x_e <<","<< y_e <<") solved " + "STOP until ctr arrival"<< std::endl; + + }else{ + + alarm_mode = 1; + + if (debug_) + std::cout << NOW << " UwAUVErrModule::recv(Packet *p) MAYBE there is an error ("<< x_e <<","<< y_e <<") solved " + "continue tx"<< std::endl; + } + } last_sn_confirmed = uwAUVh->sn(); } @@ -394,3 +414,90 @@ void UwAUVErrorModule::recv(Packet* p) { } } + +double UwAUVErrorModule::getErrorProb(){ + + 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); // Adjust the standard deviation using the variance + + // Generate a random value from the Gaussian distribution + double noise = n_dis(gen); + + double m = t_e + noise; + + //double p_e = QFunction(m); + + // Calculate the error probability + double p_e = std::erfc(((th_ne - m) / std::sqrt(2.0)) / sigma); // prob of true error (t_e) greater than th_ne + + + //double th_5sig = std::erfc((5*sigma) / std::sqrt(2)) / 2; + + if (p_e >= 0.001){ //if p_e is small enough --> no error, otherwise gray zone + alarm_mode = 1; + } + + return m; + + +} + + +double UwAUVErrorModule::getErrorProb(double t_e){ + + std::random_device rd; + std::mt19937 gen(rd()); + + std::normal_distribution<> n_dis(0.0, sigma); // Adjust the standard deviation using the variance + + // Generate a random value from the Gaussian distribution + double noise = n_dis(gen); + + double m = t_e + noise; + + //double p_e = QFunction(m); + + // Calculate the probability using std::erfc + double p_e = std::erfc(((th_ne - m) / std::sqrt(2.0)) / sigma); // prob of t_e grater than th_ne + + + double th_5sig = std::erfc((5*sigma) / std::sqrt(2)) / 2; + + //if (p_e >= th_5sig){ //if p_e is small enough --> no error + // alarm_mode = 1; + //} + + return m; + + +} + +/*double QFunction(double x) { + + x = (th_ne - x)/ sigma; + + if (x < 0.0) { + return 1.0 - QFunction(-x); // Q(-x) = 1 - Q(x) + } + + double constant = 1.0 / std::sqrt(2.0 * M_PI); + double xSquared = x * x; + double xPower = x; + double qValue = 0.0; + double term = constant * std::exp(-0.5 * xSquared); + + for (int i = 1; i <= 100; i++) { + qValue += term; + term *= -xSquared / i; + } + + return qValue; +}*/ + + diff --git a/DESERT_Addons/uwauv/uwauverror-module.h b/DESERT_Addons/uwauv/uwauverror-module.h index ec01be1a..3191f43e 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.h +++ b/DESERT_Addons/uwauv/uwauverror-module.h @@ -48,6 +48,7 @@ #include "uwsmeposition.h" #include #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. */ @@ -209,10 +210,18 @@ class UwAUVErrorModule : public UwCbrModule { float x_e; float y_e; float error_p; - bool alarm_mode; + int alarm_mode; private: + double speed; + virtual double getErrorProb(); + virtual double getErrorProb(double t_e); + //virtual double QFunction(double x); + double t_e; // True error in that point + double sigma; // standard deviation + double th_ne; // if x < th_e NO error + }; #endif // UWAUVError_MODULE_H diff --git a/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.cpp b/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.cpp index 03a25c42..14888e38 100644 --- a/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.cpp +++ b/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.cpp @@ -60,7 +60,7 @@ static class UWSMEPositionClass : public TclClass UWSMEPosition::UWSMEPosition() : UWSMPosition() - , alarm_mode(false) + , alarm_mode(false) { bind("debug_", &debug_); } diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl index a84755f6..fcfaf39a 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl @@ -25,8 +25,12 @@ proc createASV { id } { Module/UW/AUV/CER set period_ 500 Module/UW/AUV/CER set PoissonTraffic_ 1 Module/UW/AUV/CER set traffic_type_ 3 - Module/UW/AUV/CER set debug_ 0 + Module/UW/AUV/CER set debug_ 1 Module/UW/AUV/CER set log_flag_ 1 + Module/UW/AUV/CER set sigma_ 0.01 + Module/UW/AUV/CER set th_ne_ 0.99 + + for {set id1 0} {$id1 <= $opt(n_auv)} {incr id1} { set asv_err($id1) [new Module/UW/AUV/CER] } diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl index 12af1264..31d75cf1 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl @@ -28,8 +28,11 @@ proc createAUV { id } { Module/UW/AUV/ERR set period_ 500 Module/UW/AUV/ERR set PoissonTraffic_ 1 Module/UW/AUV/ERR set traffic_type_ 3 - Module/UW/AUV/ERR set debug_ 0 + Module/UW/AUV/ERR set debug_ 1 Module/UW/AUV/ERR set log_flag_ 1 + Module/UW/AUV/ERR set sigma_ 0.01 + Module/UW/AUV/ERR set th_ne_ 0.99 + set auv_err($id) [new Module/UW/AUV/ERR] @@ -41,12 +44,12 @@ proc createAUV { id } { set ctr_auv($id) [new Module/UW/MULTI_TRAFFIC_RANGE_CTR] - Module/UW/TDMA set frame_duration $opt(tdma_frame) - Module/UW/TDMA set fair_mode 1 - Module/UW/TDMA set guard_time $opt(tdma_gard) - Module/UW/TDMA set tot_slots $opt(n_auv) - Module/UW/TDMA set debug_ 0 - Module/UW/TDMA set queue_size_ 100 + #Module/UW/TDMA set frame_duration $opt(tdma_frame) + #Module/UW/TDMA set fair_mode 1 + #Module/UW/TDMA set guard_time $opt(tdma_gard) + #Module/UW/TDMA set tot_slots $opt(n_auv) + #Module/UW/TDMA set debug_ 0 + #Module/UW/TDMA set queue_size_ 100 Module/UW/CSMA_ALOHA set listen_time_ [expr 1.0e-12] Module/UW/CSMA_ALOHA set wait_costant_ [expr 1.0e-12] diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_coordinates.py b/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_coordinates.py index c959f6ca..8c1a7091 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_coordinates.py +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_coordinates.py @@ -67,7 +67,7 @@ def plot_movement_log(file_path,t,axis): 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) +#plot_coordinates(file_path,X_0,Y_0,Z_0) X_1a = [] Y_1a = [] @@ -75,13 +75,13 @@ def plot_movement_log(file_path,t,axis): #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) +#plot_coordinates(file_path,X_1a,Y_1a,Z_1a) fig = plt.figure() ax = plt.subplot() -ax.plot(X_1a, Y_1a,'y-', label='auv_1') +ax.plot(X_1, Y_1,'y.', label='auv_1') 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') @@ -105,17 +105,25 @@ def plot_movement_log(file_path,t,axis): Y_e_c = [] file_path = 'error_calling_log.csv' # Replace with your file pathplot_coordinates(file_path) plot_movement_log(file_path,X_e_c,Y_e_c) + +X_e_s = [] +Y_e_s = [] +file_path = 'error_log_a.csv' # Replace with your file pathplot_coordinates(file_path) +plot_movement_log(file_path,X_e_s,Y_e_s) + X_e = [] Y_e = [] file_path = 'error_log.csv' # Replace with your file pathplot_coordinates(file_path) plot_movement_log(file_path,X_e,Y_e) + fig = plt.figure() ax = plt.subplot() -ax.plot(Z_1a, X_1a,'y-', label='auv_1') -ax.plot(Z_0, X_0,'m-', label='auv_1') +ax.plot(Z_1a, X_1a,'y--', label='auv_1') +ax.plot(Z_0, X_0,'m--', label='auv_1') ax.plot(t, Axis,'k.', label='auv_1') ax.plot(s_t, s_ax,'g--', label='asv') ax.plot(X_e_c, Y_e_c, 'b^',label='error_called') +ax.plot(X_e_s, Y_e_s, 'bx',label='error_solved') ax.plot(X_e, Y_e, 'rx',label='error_Solved') ax.legend() plt.show() diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl index 1c0ba1be..ec0dcbae 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl @@ -144,20 +144,20 @@ set opt(ack_mode) "setNoAckMode" set opt(txpower) 135.0 #set opt(txpower_hf) 135.0 -set opt(tdma_frame) 20 -set opt(tdma_gard) 1 +#set opt(tdma_frame) 20 +#set opt(tdma_gard) 1 set opt(pktsize) 125 set opt(ctr_period) 60 -set opt(pktsize_monitoring) 50 -set opt(auv_period) 40 +set opt(pktsize_monitoring) 125 +set opt(auv_period) 60 #set opt(pktsize_control) 100 #set opt(cbr_period_control) [expr $opt(cbr_period_monitoring)*4] -set opt(pktsize_error) 1000 -set opt(auv_period_error) [expr $opt(auv_period)*5] +set opt(pktsize_error) 100 +set opt(auv_period_error) 60 set opt(op_freq) 10000000 set opt(op_bw) 100000 @@ -233,16 +233,16 @@ Module/UW/AUV set PoissonTraffic_ 1 Module/UW/AUV set debug_ 0 #UW/AUV/ERR -Module/UW/AUV/ERR set packetSize_ $opt(pktsize) -Module/UW/AUV/ERR set period_ $opt(auv_period) -Module/UW/AUV/ERR set PoissonTraffic_ 1 -Module/UW/AUV/ERR set debug_ 0 +#Module/UW/AUV/ERR set packetSize_ $opt(pktsize) +#Module/UW/AUV/ERR set period_ $opt(auv_period) +#Module/UW/AUV/ERR set PoissonTraffic_ 1 +#Module/UW/AUV/ERR set debug_ 0 #UW/AUV/CERR -Module/UW/AUV/CER set packetSize_ $opt(pktsize) -Module/UW/AUV/CER set period_ $opt(auv_period) -Module/UW/AUV/CER set PoissonTraffic_ 1 -Module/UW/AUV/CER set debug_ 0 +#Module/UW/AUV/CER set packetSize_ $opt(pktsize) +#Module/UW/AUV/CER set period_ $opt(auv_period) +#Module/UW/AUV/CER set PoissonTraffic_ 1 +#Module/UW/AUV/CER set debug_ 1 # BPSK @@ -264,10 +264,10 @@ 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 -Module/UW/TDMA set frame_duration $opt(tdma_frame) -Module/UW/TDMA set fair_mode 1 -Module/UW/TDMA set guard_time $opt(tdma_gard) -Module/UW/TDMA set tot_slots $opt(n_auv) +#Module/UW/TDMA set frame_duration $opt(tdma_frame) +#Module/UW/TDMA set fair_mode 1 +#Module/UW/TDMA set guard_time $opt(tdma_gard) +#Module/UW/TDMA set tot_slots $opt(n_auv) # PHY @@ -477,28 +477,21 @@ for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { #$ns at $opt(stoptime) "$mac_op_asv stop" proc update_and_check {t} { - set outfile_auv0 [open "test_uwauv0_results.csv" "a"] - set outfile_auv1 [open "test_uwauv1_results.csv" "a"] + 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 - # $position_asv update - # puts $outfile "positions AUV: x( $id1 ) = [$auv_app($id1) getX], y = [$auv_app($id1) getY], z = [$auv_app($id1) getZ]" - # puts $outfile "positions AUV_ERR: x( $id1 ) = [$auv_err($id1) getX], y = [$auv_err($id1) getY], z = [$auv_err($id1) getZ]" - #} + 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_auv(0) update - $position_auv(1) update - $position_asv update - puts $outfile_auv0 "$t,[$auv_app(0) getX],[$auv_app(0) getY],[$auv_app(0) getZ]" - puts $outfile_auv1 "$t,[$auv_app(1) getX],[$auv_app(1) getY],[$auv_app(1) 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_auv0 - close $outfile_auv1 + close $outfile_auv close $outfile_asv From be0f558644d8da48187ef11f286ccca700ba82b9 Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Mon, 3 Jul 2023 14:46:42 +0200 Subject: [PATCH 13/36] add basic version --- DESERT_Addons/uwauv/uwauv-init.tcl | 44 +- DESERT_Addons/uwauv/uwauvctrer-b-module.cc | 460 +++++++++++++++++++++ DESERT_Addons/uwauv/uwauvctrer-b-module.h | 230 +++++++++++ DESERT_Addons/uwauv/uwauvctrer-module.cc | 301 +++++++++----- DESERT_Addons/uwauv/uwauvctrer-module.h | 4 +- DESERT_Addons/uwauv/uwauverror-b-module.cc | 371 +++++++++++++++++ DESERT_Addons/uwauv/uwauverror-b-module.h | 222 ++++++++++ DESERT_Addons/uwauv/uwauverror-module.cc | 115 ++++-- DESERT_Addons/uwauv/uwauverror-module.h | 9 +- 9 files changed, 1591 insertions(+), 165 deletions(-) create mode 100644 DESERT_Addons/uwauv/uwauvctrer-b-module.cc create mode 100644 DESERT_Addons/uwauv/uwauvctrer-b-module.h create mode 100644 DESERT_Addons/uwauv/uwauverror-b-module.cc create mode 100644 DESERT_Addons/uwauv/uwauverror-b-module.h diff --git a/DESERT_Addons/uwauv/uwauv-init.tcl b/DESERT_Addons/uwauv/uwauv-init.tcl index 39db2a7d..76bf500e 100644 --- a/DESERT_Addons/uwauv/uwauv-init.tcl +++ b/DESERT_Addons/uwauv/uwauv-init.tcl @@ -80,12 +80,12 @@ Module/UW/AUV/ERR instproc init {args} { $self settag "UW/AUV/ERR" } -Module/UW/AUV/CER set packetSize_ 500 +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_ 1 +Module/UW/AUV/CER set PoissonTraffic_ 0 Module/UW/AUV/CER set drop_out_of_order_ 1 Module/UW/AUV/CER set adaptiveRTO_ 0 @@ -94,17 +94,35 @@ Module/UW/AUV/CER instproc init {args} { $self settag "UW/AUV/CER" } -#Module/UW/TDMA set slot_status 0 -#Module/UW/TDMA set num_hosts 2 -#Module/UW/TDMA set host_id 2 -#Module/UW/TDMA set frame_time 10 -#Module/UW/TDMA set guard_time 1 -#Module/UW/TDMA set slot_duration 4 - -#Module/UW/TDMA instproc init {args} { -# $self next $args -# $self settag "UW/TDMA" -#} +Module/UW/AUV/CEB set packetSize_ 100 +Module/UW/AUV/CEB set period_ 60 +Module/UW/AUV/CEB set destPort_ 0 +Module/UW/AUV/CEB set destAddr_ 0 +Module/UW/AUV/CEB set debug_ 0 +Module/UW/AUV/CEB set PoissonTraffic_ 0 +Module/UW/AUV/CEB set drop_out_of_order_ 1 +Module/UW/AUV/CEB set adaptiveRTO_ 0 + +Module/UW/AUV/CEB instproc init {args} { + $self next $args + $self settag "UW/AUV/CEB" +} + +Module/UW/AUV/ERB set packetSize_ 100 +Module/UW/AUV/ERB set period_ 60 +Module/UW/AUV/ERB set destPort_ 0 +Module/UW/AUV/ERB set destAddr_ 0 +Module/UW/AUV/ERB set debug_ 0 +Module/UW/AUV/ERB set PoissonTraffic_ 0 +Module/UW/AUV/ERB set drop_out_of_order_ 1 +Module/UW/AUV/ERB set adaptiveRTO_ 0 + +Module/UW/AUV/ERB instproc init {args} { + $self next $args + $self settag "UW/AUV/ERB" +} + + Position/UWSM set debug_ 0 Position/UWSME set debug_ 0 diff --git a/DESERT_Addons/uwauv/uwauvctrer-b-module.cc b/DESERT_Addons/uwauv/uwauvctrer-b-module.cc new file mode 100644 index 00000000..12b4b77f --- /dev/null +++ b/DESERT_Addons/uwauv/uwauvctrer-b-module.cc @@ -0,0 +1,460 @@ +// +// 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 uwauvctrer-b-module.cc +* @author Filippo Campagnaro, Alessia Ortile +* @version 1.0.0 +* +* \brief Provides the UWAUVCtrEr class implementation. +* +* Provides the UWAUVCtrEr class implementation. +*/ + +#include "uwauvctrer-b-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; +/** +* Adds the module for UwAUVModuleClass in ns2. +*/ + +/** +* Class that represents the binding with the tcl configuration script +*/ +static class UwAUVCtrErBModuleClass : public TclClass { +public: + + /** + * Constructor of the class + */ + UwAUVCtrErBModuleClass() : TclClass("Module/UW/AUV/CEB") { + } + + /** + * Creates the TCL object needed for the tcl language interpretation + * @return Pointer to an TclObject + */ + TclObject* create(int, const char*const*) { + return (new UwAUVCtrErBModule()); + } +} class_module_uwAUV_error; + + +UwAUVCtrErBModule::UwAUVCtrErBModule(UWSMEPosition* p) + : UwCbrModule() + , ack(0) + , last_sn_confirmed(0) + , sn(0) + , ackTimeout(10) + , drop_old_waypoints(1) + , log_flag(0) + , period(60) + , speed(4) +{ + posit=p; + x_sorg = posit->getX(); + y_sorg = posit->getY(); + + bind("ackTimeout_", (int*) &ackTimeout); + bind("drop_old_waypoints_", (int*) &drop_old_waypoints); + bind("log_flag_", (int*) &log_flag ); + bind("period_", (int*) &period ); + + if (ackTimeout < 0) { + cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" + << std::endl; + ackTimeout = 10; + } +} + +UwAUVCtrErBModule::UwAUVCtrErBModule() + : UwCbrModule() + , ack(0) + , last_sn_confirmed(0) + , sn(0) + , ackTimeout(10) + , drop_old_waypoints(1) + , log_flag(0) + , period(60) + , speed(4) + +{ + p = NULL; + UWSMEPosition p = UWSMEPosition(); + posit=&p; + x_sorg = posit->getX(); + y_sorg = posit->getY(); + + bind("ackTimeout_", (int*) &ackTimeout); + bind("drop_old_waypoints_", (int*) &drop_old_waypoints); + bind("log_flag_", (int*) &log_flag ); + bind("period_", (int*) &period ); + + if (ackTimeout < 0) { + cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" + << std::endl; + ackTimeout = 10; + } + +} + +UwAUVCtrErBModule::~UwAUVCtrErBModule() {} + +int UwAUVCtrErBModule::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) { + UWSMEPosition* p = dynamic_cast (tcl.lookup(argv[2])); + posit = p; + return TCL_OK; + } else + if (strcasecmp(argv[1], "setSpeed") == 0) { + speed = atof(argv[2]); + return TCL_OK; + } + } + + return UwCbrModule::command(argc,argv); +} + +void UwAUVCtrErBModule::start() {} + +void UwAUVCtrErBModule::setPosition(UWSMEPosition* p){ + + posit = p; + x_sorg = posit->getX(); + y_sorg = posit->getY(); + +} + +void UwAUVCtrErBModule::transmit() { + + sendPkt(); + + if (debug_) { + std::cout << NOW << " UwAUVCtrErBModule::Sending pkt with period: " << period + << std::endl; + } + + sendTmr_.resched(period); +} + +float UwAUVCtrErBModule::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); + +} + +void UwAUVCtrErBModule::initPkt(Packet* p) { + + hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); + hdr_uwcbr *uwcbrh = HDR_UWCBR(p); + bool found = false; + + uwAUVh->ack() = ack; + ack = 0; + uwAUVh->error() = 0; + + + + if (alarm_mode){ + + if ((getDistance(posit->getX(),posit->getY(),x_err,y_err) == 0.0)){ //If in the right position + + found = true; + x_s = x_err; + y_s = y_err; + + if (debug_) + std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p) SV reached the destination"<< std::endl; + + + }else if((getDistance(x_sorg,y_sorg,x_err,y_err) < getDistance(posit->getX(),posit->getY(),x_sorg,y_sorg))){ //if the right position // has been already passed + + found = true; + x_s = x_err; + y_s = y_err; + + + if (debug_) + std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p) SV has gone too far "<< std::endl; + + } + + if (found){ + + uwAUVh->error() = -1; + alarm_mode = false; + uwAUVh->sn() = ++sn; + uwAUVh->x() = x_s; + uwAUVh->y() = y_s; + this->p = p; + + if (log_flag == 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 << " UwAUVCtrErBModule::initPkt(Packet *p) ERROR ("<< x_err << "," << y_err << ") SOLVED" + << std::endl; + } + + /* TO DO */ + /* CHECK ALL THE STATE OF THE ERROR IN THE QUEUE, IF ONE OF THEM IS 2 THEN GO THERE*/ + + if (!alarm_queue.empty()){ //take care of the next error + + x_err = alarm_queue[0][0]; + y_err = alarm_queue[0][1]; + + posit->setdest(x_err,y_err,posit->getZ(),speed); + alarm_mode = true; + + alarm_queue.erase(alarm_queue.begin()); + + x_sorg = posit->getX(); + y_sorg = posit->getY(); + + if (debug_) { + std::cout << NOW << " UwAUVCtrErrModule::initPkt(Packet *p) SV picked a new " + "error from the queue: X = " << x_err << ", Y = " << y_err<< std::endl; + } + } + + }else{ + + uwAUVh->error() = 1; + uwAUVh->sn() = ++sn; + uwAUVh->x() = x_err; + uwAUVh->y() = y_err; + this->p = p; + + if (debug_) { + std::cout << NOW << " UwAUVCtrErBModule::initPkt(Packet *p) ERROR ("<< x_err << "," << y_err << ") still to solve" + << std::endl; + } + + } + + } + + + if (debug_) { + std::cout << NOW << " UwAUVCtrErBModule::initPkt(Packet *p) ACK recv" + << std::endl; + } + + UwCbrModule::initPkt(p); + + if (debug_) { + std::cout << NOW << " UwAUVCtrErBModule::initPkt(Packet *p) setting last ack" + << std::endl; + } + +} + +void UwAUVCtrErBModule::recv(Packet* p, Handler* h) { + recv(p); +} + +void UwAUVCtrErBModule::recv(Packet* p) { + + hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); + bool exist = false; + + + if(uwAUVh->ack() == sn + 1) { //ack received + this->p = NULL; + } + + + if(uwAUVh->ack() > 0 && debug_) + std::cout << NOW << " UwAUVErrorModule::recv(Packet *p) error ACK " + << "received " << uwAUVh->ack()<< std::endl; + else if((uwAUVh->ack())<0 && debug_) + std::cout << NOW << " UwAUVErrorModule::recv(Packet *p) error NACK " + <<"received"<< std::endl; + + + + if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { //obsolete packets + 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 + + 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->setdest(x_err,y_err,posit->getZ(),speed); + + alarm_mode = 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_flag == 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{ + + x_err = alarm_queue[0][0]; + y_err = alarm_queue[0][1]; + posit->setdest(x_err,y_err,posit->getZ(),speed); + + alarm_mode = true; + + x_sorg = posit->getX(); + y_sorg = posit->getY(); + + exist = false; + + for (const auto& vec : alarm_queue) { + // Controlla se le coordinate corrispondono + if (vec[0] == uwAUVh->x() && vec[1] == uwAUVh->y()) { + exist = true; + break; + } + } + + if (!exist){ + alarm_queue.push_back({uwAUVh->x(),uwAUVh->y()}); + } + + alarm_queue.erase(alarm_queue.begin()); + + if (log_flag == 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) { + // Controlla se le coordinate corrispondono + 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(); + } + + ack = last_sn_confirmed+1; + + UwCbrModule::recv(p); + UwCbrModule::sendPkt(); +} + + diff --git a/DESERT_Addons/uwauv/uwauvctrer-b-module.h b/DESERT_Addons/uwauv/uwauvctrer-b-module.h new file mode 100644 index 00000000..605675f4 --- /dev/null +++ b/DESERT_Addons/uwauv/uwauvctrer-b-module.h @@ -0,0 +1,230 @@ +// +// 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 uwauvctr-module.h +* @author Filippo Campagnaro, Alessia Ortile +* @version 1.0.0 +* +* \brief Provides the definition of the class UWAUV. +* +* Provides the definition of the class UWAUVCTR, based on UwCbr. +* UWAUVCTR can manage no more than 2^16 packets. If a module generates more +* than 2^16 packets, they will be dropped, according with UwCbr. +* UWAUVCTR sends control packets containing the next waypoint that has to be +* reach by a AUV. In addition it receives monitoring packets containing the current +* AUV position and acks of the sent packets. Whether the ack is not received, the +* control packet is resent, according to the priority. In particular, last waypoint +* transmitted has the highest priority, whereas the others are forgotten.: +*/ + +#ifndef UWAUVError_MODULE_H +#define UWAUVError_MODULE_H +#include +#include "uwauv-packet.h" +#include "uwsmeposition.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. */ +#define HDR_UWAUV_MONITORING(p) (hdr_uwAUV_monitoring::access(p)) +#define HDR_UWAUV_CTR(p) (hdr_uwAUV_ctr::access(p)) +#define HDR_UWAUV_ERROR(p) (hdr_uwAUV_error::access(p)) +using namespace std; +class UwAUVCtrErBModule; + +/** +* 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(UwAUVCtrErBModule *m) : UwSendTimer((UwCbrModule*)(m)){ + }; +}; + + +/** +* UwAUVCtrModule class is used to manage UWAUVCtr packets and to collect statistics about them. +*/ +class UwAUVCtrErBModule : public UwCbrModule { +public: + + /** + * Constructor of UwAUVCtrModule class. + */ + UwAUVCtrErBModule(); + + /** + * Constructor of UwAUVCtrModule class with position setting. + */ + UwAUVCtrErBModule(UWSMEPosition* p); + + /** + * Destructor of UwAUVCtrModule class. + */ + virtual ~UwAUVCtrErBModule(); + + /** + * 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(UWSMEPosition* p); + + /** + * Returns the position of the AUVCtr + * + * @return the current AUVCtr position + */ + inline UWSMEPosition* getPosition() { 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*); + + /** + * Performs the reception of packets from upper and lower layers. + * + * @param Packet* Pointer to the packet will be received. + * @param Handler* Handler. + */ + virtual void recv(Packet* p, Handler* h); + + /** + * 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); } + + /** + * 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); } + + float getDistance(float x_s,float y_s, float x_d, float y_d); + + + +protected: + + UWSMEPosition* 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 ack; + int drop_old_waypoints; + 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; + int log_flag; + int ackTimeout; + float x_sorg; + float y_sorg; + double speed; + + static int alarm_mode; + static vector> alarm_queue; + +private: + + std::ofstream pos_log; + std::ofstream err_log; + std::ofstream t_err_log; + +}; + +int UwAUVCtrErBModule::alarm_mode = 0; +vector> UwAUVCtrErBModule::alarm_queue = {}; + +#endif // UWAUVCtr_MODULE_H diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.cc b/DESERT_Addons/uwauv/uwauvctrer-module.cc index ba97cceb..84751903 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.cc +++ b/DESERT_Addons/uwauv/uwauvctrer-module.cc @@ -80,6 +80,7 @@ UwAUVCtrErModule::UwAUVCtrErModule(UWSMEPosition* p) , log_flag(0) , period(60) , speed(4) + , accuracy(0.001) { posit=p; x_sorg = posit->getX(); @@ -91,6 +92,7 @@ UwAUVCtrErModule::UwAUVCtrErModule(UWSMEPosition* p) bind("period_", (int*) &period ); bind("sigma_", (double*) &sigma); bind("th_ne_", (double*) &th_ne ); + bind("accuracy_ne_", (double*) &accuracy ); if (ackTimeout < 0) { cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" @@ -109,6 +111,7 @@ UwAUVCtrErModule::UwAUVCtrErModule() , log_flag(0) , period(60) , speed(4) + , accuracy(0.001) { p = NULL; @@ -123,6 +126,7 @@ UwAUVCtrErModule::UwAUVCtrErModule() bind("period_", (int*) &period ); bind("sigma_", (double*) &sigma); bind("th_ne_", (double*) &th_ne ); + bind("accuracy_ne_", (double*) &accuracy ); if (ackTimeout < 0) { cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" @@ -214,120 +218,137 @@ void UwAUVCtrErModule::initPkt(Packet* p) { bool found = false; uwAUVh->speed() = 0; - uwAUVh->ack() = ack; + uwAUVh->ack() = ack; ack = 0; uwAUVh->error() = 0; - if(this->p == NULL){ + //if(this->p == NULL){ //TO FIX - if (error_released){ + if (error_released){ - uwAUVh->error() = -1; - uwAUVh->sn() = ++sn; - uwAUVh->x() = x_s; - uwAUVh->y() = y_s; - error_released = false; - this->p = p; + 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; + if (log_flag == 1) { + err_log.open("log/error_log.csv",std::ios_base::app); + err_log << "G,"<< NOW << "," << x_s<<","<getX(),posit->getY(),x_err,y_err) == 0.0)){ //If in the right position - - found = true; - x_s = x_err; - y_s = y_err; - - if (debug_) - std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p) SV reached the destination"<< std::endl; - - }else if((getDistance(x_sorg,y_sorg,x_err,y_err) < getDistance(posit->getX(),posit->getY(),x_sorg,y_sorg))){ //if the right position // has been already passed + }else if (alarm_mode == 2){ //I need to go there + + if ((getDistance(posit->getX(),posit->getY(),x_err,y_err) == 0.0)){ //If in the right position + + found = true; + x_s = x_err; + y_s = y_err; + + if (debug_) + std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p) SV reached the destination"<< std::endl; - found = true; - x_s = x_err; - y_s = y_err; + }else if((getDistance(x_sorg,y_sorg,x_err,y_err) < getDistance(posit->getX(),posit->getY(),x_sorg,y_sorg))){ //if the right position // has been already passed + + found = true; + x_s = x_err; + y_s = y_err; - if (debug_) - std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p) SV have gone too far "<< std::endl; - - } - if (found){ + if (debug_) + std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p) SV has gone too far "<< std::endl; - uwAUVh->error() = -1; - alarm_mode = 0; - uwAUVh->sn() = ++sn; - uwAUVh->x() = x_s; - uwAUVh->y() = y_s; - this->p = p; + } - if (log_flag == 1) { + if (found){ + + uwAUVh->error() = -1; + alarm_mode = 0; + uwAUVh->sn() = ++sn; + uwAUVh->x() = x_s; + uwAUVh->y() = y_s; + this->p = p; - err_log.open("error_log.csv",std::ios_base::app); - err_log << NOW << "," << x_s<<","<getX() << ","<< posit->getY() + << ","<< posit->getZ() << std::endl; + pos_log.close(); - x_err = alarm_queue[0][0]; - y_err = alarm_queue[0][1]; + } - posit->setdest(x_err,y_err,posit->getZ(),speed); - alarm_mode = 2; + if (debug_) { + std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) ERROR ("<< x_err << "," << y_err << ") SOLVED" + << std::endl; + } - alarm_queue.erase(alarm_queue.begin()); + /* TO DO */ + /* CHECK ALL THE STATE OF THE ERROR IN THE QUEUE, IF ONE OF THEM IS 2 THEN GO THERE*/ - x_sorg = posit->getX(); - y_sorg = posit->getY(); - - if (debug_) { - std::cout << NOW << " UwAUVCtrErrModule::initPkt(Packet *p) SV picked a new " - "error from the queue: X = " << x_err << ", Y = " << y_err<< std::endl; - } + if (!alarm_queue.empty()){ //take care of the next error - } + x_err = alarm_queue[0][0]; + y_err = alarm_queue[0][1]; - }else{ + posit->setdest(x_err,y_err,posit->getZ(),speed); + alarm_mode = 2; - uwAUVh->error() = 1; - uwAUVh->sn() = ++sn; - uwAUVh->x() = x_err; - uwAUVh->y() = y_err; - this->p = p; + alarm_queue.erase(alarm_queue.begin()); + x_sorg = posit->getX(); + y_sorg = posit->getY(); + if (debug_) { - std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) ERROR ("<< x_err << "," << y_err << ") still to solve" - << std::endl; + std::cout << NOW << " UwAUVCtrErrModule::initPkt(Packet *p) SV picked a new " + "error from the queue: X = " << x_err << ", Y = " << y_err<< std::endl; } } - } - + }else{ + + 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 (debug_) { - std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) ACK recv" - << std::endl; } + } + + + if (debug_) { + std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) ACK recv" + << std::endl; + } + //Retransmission - }else{ + /*}else{ uwAUVh->error() = -1; uwAUVh->sn() = sn; @@ -339,7 +360,7 @@ void UwAUVCtrErModule::initPkt(Packet* p) { std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) Retransmission ERROR ("<< x_s << "," << y_s << ") solved" << std::endl; } - } + }*/ UwCbrModule::initPkt(p); @@ -348,15 +369,6 @@ void UwAUVCtrErModule::initPkt(Packet* p) { << std::endl; } - if (log_flag == 1) { - - pos_log.open("position_log.csv",std::ios_base::app); - pos_log << NOW << "," << posit->getX() << ","<< posit->getY() - << ","<< posit->getZ() << std::endl; - pos_log.close(); - - } - } void UwAUVCtrErModule::recv(Packet* p, Handler* h) { @@ -397,7 +409,7 @@ void UwAUVCtrErModule::recv(Packet* p) { }else{ // error of some kind - int status = checkError(uwAUVh->error(),1); + int status = checkError(uwAUVh->error(),1, uwAUVh->x(), uwAUVh->y()); bool exists = false; if (!gray_queue.empty()){ @@ -417,16 +429,15 @@ void UwAUVCtrErModule::recv(Packet* p) { if(exists){ if (debug_) - std::cout << NOW << " UwAUVCtrErrModule::recv(Pakct p) gray_queue error value updated, old error("<< gray_queue[i][2] << "),"; + std::cout << NOW << " UwAUVCtrErrModule::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]); + status = checkError(gray_queue[i][2],gray_queue[i][3], uwAUVh->x(), uwAUVh->y()); if (debug_) - std::cout << " updated error("<< gray_queue[i][2] << ")" << std::endl; - + std::cout << " updated error("<< (gray_queue[i][2]/gray_queue[i][3]) << ")" << std::endl; } } @@ -436,9 +447,15 @@ void UwAUVCtrErModule::recv(Packet* p) { if(!exists){ gray_queue.push_back({uwAUVh->x(), uwAUVh->y(), uwAUVh->error(),1}); - if (debug_) + 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] << std::endl; + std::cout << NOW << " UwAUVCtrErrModule::recv(Pakct p) Next gray error = " << (gray_queue[0][2]/gray_queue[0][3]) << std::endl; + } + //if (log_flag == 1) { + // err_log.open("log/error_log.csv",std::ios_base::app); + // err_log << "G,"<< NOW << "," << uwAUVh->x() <<","<y()<<", ON"<< std::endl; + // err_log.close(); + //} } @@ -465,6 +482,22 @@ void UwAUVCtrErModule::recv(Packet* p) { 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_flag == 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 (log_flag == 1) { + err_log.open("log/error_log.csv",std::ios_base::app); + err_log << "R,"<< NOW << "," << x_err <<","<getX(); y_sorg = posit->getY(); + exists = false; + + for (const auto& vec : alarm_queue) { + // Controlla se le coordinate corrispondono + if (vec[0] == uwAUVh->x() && vec[1] == uwAUVh->y()) { + exists = true; + break; + } + } + + if (!exists){ + alarm_queue.push_back({uwAUVh->x(),uwAUVh->y()}); + if (log_flag == 1) { + err_log.open("log/error_log.csv",std::ios_base::app); + err_log << "R,"<< NOW << "," << uwAUVh->x() <<","<< uwAUVh->y() <<", ON"<< std::endl; + err_log.close(); + } + } + alarm_queue.erase(alarm_queue.begin()); - alarm_queue.push_back({uwAUVh->x(),uwAUVh->y()}); + + if (log_flag == 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_) @@ -488,12 +548,28 @@ void UwAUVCtrErModule::recv(Packet* p) { }else{ - alarm_queue.push_back({uwAUVh->x(),uwAUVh->y()}); + exists = false; + + for (const auto& vec : alarm_queue) { + // Controlla se le coordinate corrispondono + if (vec[0] == uwAUVh->x() && vec[1] == uwAUVh->y()) { + exists = true; + break; + } + } + + if (!exists){ + alarm_queue.push_back({uwAUVh->x(),uwAUVh->y()}); + if (log_flag == 1) { + err_log.open("log/error_log.csv",std::ios_base::app); + err_log << "R,"<< NOW << "," << uwAUVh->x() <<","<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; - } @@ -504,6 +580,13 @@ void UwAUVCtrErModule::recv(Packet* p) { error_released = true; x_s = uwAUVh->x(); y_s = uwAUVh->y(); + + if (log_flag == 1) { + err_log.open("log/error_log.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; } @@ -517,19 +600,9 @@ void UwAUVCtrErModule::recv(Packet* p) { UwCbrModule::recv(p); UwCbrModule::sendPkt(); - - - if (log_flag == 1) { - pos_log.open("position_log.csv",std::ios_base::app); - pos_log<< NOW << ","<getX() << ","<< posit->getY() - << ","<< posit->getZ() << std::endl; - pos_log.close(); - } - - } -int UwAUVCtrErModule::checkError(double m, int n_pkt){ +int UwAUVCtrErModule::checkError(double m, int n_pkt, float x, float y){ // Calculate the probability using std::erfc double p_e = std::erfc(((th_ne - (m/n_pkt)) * std::sqrt(n_pkt) / std::sqrt(2.0)) / sigma); // prob of true error (t_e) greater than th_ne @@ -537,12 +610,24 @@ int UwAUVCtrErModule::checkError(double m, int n_pkt){ int status; - if (p_e <= 0.001){ //if p_e is small enough --> no error + if (p_e <= accuracy){ //if p_e is small enough --> no error // NO ERROR + if (log_flag == 1) { + t_err_log.open("log/true_error_log.csv",std::ios_base::app); + t_err_log << NOW << "," << x <<","<< y <<","<< 0 << std::endl; + t_err_log.close(); + } status = 0; - }else if (p_e >= (1-0.001)){ + }else if (p_e >= (1-accuracy)){ // FOR SURE ERROR status = 2; + + if (log_flag == 1) { + t_err_log.open("log/true_error_log.csv",std::ios_base::app); + t_err_log << NOW << "," << x <<","<< y <<","<< 1 << std::endl; + t_err_log.close(); + } + }else{ //I NEED MORE DATA status = 1; diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.h b/DESERT_Addons/uwauv/uwauvctrer-module.h index 69db2bc9..7cd9f6ec 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.h +++ b/DESERT_Addons/uwauv/uwauvctrer-module.h @@ -225,11 +225,13 @@ class UwAUVCtrErModule : public UwCbrModule { private: - virtual int checkError(double m, int n_pkt); + virtual 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; }; diff --git a/DESERT_Addons/uwauv/uwauverror-b-module.cc b/DESERT_Addons/uwauv/uwauverror-b-module.cc new file mode 100644 index 00000000..023c23d9 --- /dev/null +++ b/DESERT_Addons/uwauv/uwauverror-b-module.cc @@ -0,0 +1,371 @@ +// +// 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 uwauv-module.cc +* @author Filippo Campagnaro, Alessia Ortile +* @version 1.0.0 +* +* \brief Provides the UWAUVError class implementation. +* +*/ + +#include "uwauverror-b-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; +/** +* Adds the header for hdr_uwAUVError packets in ns2. +*/ +/** +* Adds the module for UwAUVModuleClass in ns2. +*/ + +/** + * Class that represents the binding with the tcl configuration script + */ +static class UwAUVErrorBModuleClass : public TclClass { +public: + + /** + * Constructor of the class + */ + UwAUVErrorBModuleClass() : TclClass("Module/UW/AUV/ERB") { + } + + /** + * Creates the TCL object needed for the tcl language interpretation + * @return Pointer to an TclObject + */ + TclObject* create(int, const char*const*) { + return (new UwAUVErrorBModule()); + } +} class_module_uwAUV; + + + +UwAUVErrorBModule::UwAUVErrorBModule() + : UwCbrModule() + , last_sn_confirmed(0) + , sn(0) + , ack(0) + , ackPolicy(ACK_PIGGYBACK) + , ackTimeout(10) + , ackNotPgbk(0) + , drop_old_waypoints(1) + , log_flag(0) + , period(60) + , error_p(0.001) + , alarm_mode(0) + , speed(1) +{ + UWSMEPosition p = UWSMEPosition(); + posit=&p; + bind("ackTimeout_", (int*) &ackTimeout); + bind("drop_old_waypoints_", (int*) &drop_old_waypoints); + bind("log_flag_", (int*) &log_flag ); + bind("period_", (int*) &period ); + bind("error_p_", (int*) &error_p ); + if (ackTimeout < 0) { + cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" + << std::endl; + ackTimeout = 10; + } + + +} + +UwAUVErrorBModule::UwAUVErrorBModule(UWSMEPosition* p) + : UwCbrModule() + , last_sn_confirmed(0) + , sn(0) + , ack(0) + , ackPolicy(ACK_PIGGYBACK) + , ackTimeout(10) + , ackNotPgbk(0) + , drop_old_waypoints(1) + , log_flag(0) + , period(60) + , error_p(0.001) + , alarm_mode(0) + , speed(1) +{ + posit = p; + bind("ackTimeout_", (int*) &ackTimeout); + bind("drop_old_waypoints_", (int*) &drop_old_waypoints); + bind("log_flag_", (int*) &log_flag ); + bind("period_", (int*) &period ); + bind("error_p_", (int*) &error_p ); + + if (ackTimeout < 0) { + cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" + << std::endl; + ackTimeout = 10; + } + + + +} + +UwAUVErrorBModule::~UwAUVErrorBModule() {} + +void UwAUVErrorBModule::setPosition(UWSMEPosition* p){ + posit = p; +} + +int UwAUVErrorBModule::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(strcasecmp(argv[1], "getAckNotPgbk") == 0) { + tcl.resultf("%d", ackNotPgbk); + return TCL_OK; + } + } + else if(argc == 3){ + if (strcasecmp(argv[1], "setPosition") == 0) { + UWSMEPosition* p = dynamic_cast (tcl.lookup(argv[2])); + posit=p; + tcl.resultf("%s", "position Setted\n"); + return TCL_OK; + } + 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; + } + } + if (strcasecmp(argv[1], "setAckTimeout") == 0) { + ackTimeout = 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 UwAUVErrorBModule::transmit() { + sendPkt(); + + if (debug_) { + std::cout << NOW << " UwAUVErrorBModule::Sending pkt with period: " << period + << std::endl; + } + + + sendTmr_.resched(period); +} + +void UwAUVErrorBModule::initPkt(Packet* p) { + + hdr_uwcbr *uwcbrh = HDR_UWCBR(p); + hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); + + uwAUVh->ack() = ack; + ack = 0; + uwAUVh->error() = 0; + + if (!alarm_mode){ + + std::random_device rd; + std::mt19937 generator(rd()); + std::uniform_real_distribution distrib(0.0, 1.0); + + double randomValue = distrib(generator) ; + + if(randomValue < error_p){ + + 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; + + if (log_flag == 1) { + err_log.open("log/error_log.csv",std::ios_base::app); + err_log << "E,"<< NOW << "," << x_e <<","<< y_e <<", ON"<< std::endl; + 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_flag == 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 UwAUVErrorBModule::recv(Packet* p, Handler* h) { + recv(p); +} + +void UwAUVErrorBModule::recv(Packet* p) { + + hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); + + if(uwAUVh->ack() == sn + 1) { + this->p = NULL; + } + + if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { //obsolete packets + + if (debug_) { + std::cout << NOW << " UwAUVErrModule::old error with sn " + << uwAUVh->sn() << " dropped " << std::endl; + } + + } else { //packet in order + + if (alarm_mode && uwAUVh->x() == x_e && uwAUVh->y() == y_e){ //Valid pkt refering to my error + + if (uwAUVh->error() < 0 ){ + + posit->setAlarm(false); + alarm_mode = 0; + posit->setdest(posit->getXdest(),posit->getYdest(),posit->getZdest(),speed); + sendTmr_.force_cancel(); + sendTmr_.resched(period); + + if (log_flag == 1) { + err_log.open("log/error_log.csv",std::ios_base::app); + err_log << "E,"<< NOW << "," << x_e <<","<< y_e <<", OFF"<< std::endl; + err_log.close(); + } + + 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 = true; + + 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; + + } + } + + last_sn_confirmed = uwAUVh->sn(); + } + + ack = last_sn_confirmed+1; + + UwCbrModule::recv(p); + UwCbrModule::sendPkt(); + + if(uwAUVh->ack() > 0 && debug_) + std::cout << NOW << " UwAUVErrorBModule::recv(Packet *p) error ACK " + << "received " << uwAUVh->ack()<< std::endl; + else if((uwAUVh->ack())<0 && debug_) + std::cout << NOW << " UwAUVErrorBModule::recv(Packet *p) error NACK " + <<"received"<< std::endl; + + if (log_flag == 1) { + out_file_stats.open("log/position_log_a.csv",std::ios_base::app); + out_file_stats << NOW << "," << posit->getX() << ","<< posit->getY() + << "," << posit->getZ() << std::endl; + out_file_stats.close(); + } + +} + diff --git a/DESERT_Addons/uwauv/uwauverror-b-module.h b/DESERT_Addons/uwauv/uwauverror-b-module.h new file mode 100644 index 00000000..870d36ef --- /dev/null +++ b/DESERT_Addons/uwauv/uwauverror-b-module.h @@ -0,0 +1,222 @@ +// +// 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 uwauv-module.h +* @author Filippo Campagnaro Alessia Ortile +* @version 1.0.0 +* +* \brief Provides the definition of the class UWAUVError. +* +* Provides the definition of the class UWAUVError, based on UwCbr. +* UWAUVError can manage no more than 2^16 packets. If a module generates more +* than 2^16 packets, they will be dropped, according with UwCbr. +* UWAUVError sends periodically monitoring packets containing information about +* the current position and acknowledges the last control packet received. +* Each control packet contains the next waypoint that has to be reach. +*/ + +#ifndef UWAUVError_MODULE_H +#define UWAUVError_MODULE_H +#include +#include +#include "uwsmeposition.h" +#include +#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. */ +#define HDR_UWAUV_MONITORING(p) (hdr_uwAUV_monitoring::access(p)) +#define HDR_UWAUV_CTR(p) (hdr_uwAUV_ctr::access(p)) +#define HDR_UWAUV_ERROR(p) (hdr_uwAUV_error::access(p)) + +using namespace std; + +class UwAUVErrorBModule; + +/** +* 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(UwAUVErrorBModule *m) : UwSendTimer((UwCbrModule*)(m)){ + }; +}; + +/** +* UwAUVModule class is used to manage UWAUV packets and to collect statistics about them. +*/ +class UwAUVErrorBModule : public UwCbrModule { +public: + + /** + * Default Constructor of UwAUVModule class. + */ + UwAUVErrorBModule(); + + /** + * Constructor with position setting of UwAUVModule class. + * + * @param UWSMEPosition* p Pointer to the AUV position + */ + UwAUVErrorBModule(UWSMEPosition* p); + + /** + * Destructor of UwAUVModule class. + */ + virtual ~UwAUVErrorBModule(); + + /** + * 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*); + + /** + * Performs the reception of packets from upper and lower layers. + * + * @param Packet* Pointer to the packet will be received. + * @param Handler* Handler. + */ + virtual void recv(Packet* p, Handler* h); + + /** + * 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 UWSMEPosition * p Pointer to the AUV position + */ + virtual void setPosition(UWSMEPosition* p); + + /** + * Returns the position of the AUV + * + * @return the current AUV position + */ + inline UWSMEPosition* getPosition() { 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 }; + + UWSMEPosition* posit; /**< AUV position.*/ + int last_sn_confirmed;/**< Sequence number of the last command Packete received.*/ + int sn; + int ack; + //int send_ack_immediately; /**< Flag either to send acks immediately or not.*/ + 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.*/ + int ackTimeout; /**< Timeout after which ACK is sent if ackPolicy = ACK_PGBK_OR_TO. */ + 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_flag; /**< Flag to enable log file writing.*/ + Packet* p; + 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; + float y_e; + int alarm_mode; + +private: + + double speed; + double error_p; + + +}; + +#endif // UWAUVError_MODULE_H diff --git a/DESERT_Addons/uwauv/uwauverror-module.cc b/DESERT_Addons/uwauv/uwauverror-module.cc index 7b502650..ef66383e 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.cc +++ b/DESERT_Addons/uwauv/uwauverror-module.cc @@ -87,9 +87,10 @@ UwAUVErrorModule::UwAUVErrorModule() , drop_old_waypoints(1) , log_flag(0) , period(60) - , error_p(0) + , error_m(0) , alarm_mode(0) , speed(1) + , accuracy(0.001) { UWSMEPosition p = UWSMEPosition(); posit=&p; @@ -99,6 +100,7 @@ UwAUVErrorModule::UwAUVErrorModule() bind("period_", (int*) &period ); bind("sigma_", (double*) &sigma ); bind("th_ne_", (double*) &th_ne ); + bind("accuracy_ne_", (double*) &accuracy ); if (ackTimeout < 0) { cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" << std::endl; @@ -119,9 +121,10 @@ UwAUVErrorModule::UwAUVErrorModule(UWSMEPosition* p) , drop_old_waypoints(1) , log_flag(0) , period(60) - , error_p(0) + , error_m(0) , alarm_mode(0) , speed(1) + , accuracy(0.001) { posit = p; bind("ackTimeout_", (int*) &ackTimeout); @@ -130,6 +133,7 @@ UwAUVErrorModule::UwAUVErrorModule(UWSMEPosition* p) bind("period_", (int*) &period ); bind("sigma_", (double*) &sigma); bind("th_ne_", (double*) &th_ne ); + bind("accuracy_ne_", (double*) &accuracy ); if (ackTimeout < 0) { cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" @@ -251,46 +255,53 @@ void UwAUVErrorModule::initPkt(Packet* p) { if (alarm_mode == 1){ - error_p = getErrorProb(t_e); + 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_p = getErrorProb(); + + //if(posit->getX() != x_e or posit->getY() != y_e ){ + 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){ + if (log_flag == 1) { + err_log.open("log/error_log.csv",std::ios_base::app); + err_log << "G,"<< NOW << "," << posit->getX() <<","<< posit->getY() <<", ON"<< std::endl; + err_log.close(); + } + + } + //} } if (alarm_mode == 1){ + x_e = posit->getX(); // Save error position + y_e = posit->getY(); + posit->setdest(posit->getXdest(),posit->getYdest(),posit->getZdest(),0); //STOP posit->setAlarm(true); //alarm_mode = true; - - x_e = posit->getX(); // Save error position - y_e = posit->getY(); uwAUVh->x() = x_e; uwAUVh->y() = y_e; - uwAUVh->error() = error_p; + uwAUVh->error() = error_m; this->p = p; if (debug_) { std::cout << NOW << " UwAUVErroModule::initPkt(Packet *p) " - << "ERROR ("<< x_e <<","<< y_e << "," << error_p <<"), alarm_mode = "<< alarm_mode<<", true error= "<< t_e << std::endl; - } - - if (log_flag == 1) { - err_log.open("error_calling_log.csv",std::ios_base::app); - err_log << NOW << "," << x_e <<","<< y_e << "," << posit->getZ() << "," << error_p << std::endl; - err_log.close(); - } - - if (log_flag == 1) { - out_file_stats.open("postion_log_a.csv",std::ios_base::app); - out_file_stats << NOW << "," << posit->getX() << ","<< posit->getY() - << "," << posit->getZ() << std::endl; - out_file_stats.close(); + << "ERROR ("<< x_e <<","<< y_e << "," << error_m <<"), alarm_mode = "<< alarm_mode<<", true error= "<< t_e << std::endl; } }else{ @@ -301,22 +312,28 @@ void UwAUVErrorModule::initPkt(Packet* p) { } } + + }else{ + uwAUVh->x() = x_e; + uwAUVh->y() = y_e; + uwAUVh->error() = error_m; + this->p = p; } uwAUVh->sn() = ++sn; UwCbrModule::initPkt(p); - if (debug_){ + /*if (debug_){ hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); std::cout << NOW << " UwAUVErrorModule::initPkt(Packet *p) AUV current " << "position: X = " << posit->getX() << ", Y = " << posit->getY() << std::endl; - } + }*/ if (log_flag == 1) { - out_file_stats.open("postion_log_a.csv",std::ios_base::app); + out_file_stats.open("log/position_log_a.csv",std::ios_base::app); out_file_stats << NOW << "," << posit->getX() << ","<< posit->getY() - << "," << posit->getZ() << std::endl; + << "," << posit->getZ() << ", " << posit->getSpeed()<< std::endl; out_file_stats.close(); } @@ -356,6 +373,16 @@ void UwAUVErrorModule::recv(Packet* p) { posit->setAlarm(false); alarm_mode = 0; posit->setdest(posit->getXdest(),posit->getYdest(),posit->getZdest(),speed); + sendTmr_.force_cancel(); + sendTmr_.resched(period); + + if (log_flag == 1) { + err_log.open("log/error_log.csv",std::ios_base::app); + err_log << "W,"<< NOW << "," << x_e <<","<< y_e <<", ON"<< std::endl; + err_log.close(); + } + + if (debug_) { @@ -363,18 +390,12 @@ void UwAUVErrorModule::recv(Packet* p) { "AUV can move again with speed=" << posit->getSpeed()<< std::endl; } - if (log_flag == 1) { - err_solved_log.open("error_log_a.csv",std::ios_base::app); - err_solved_log << NOW << "," << posit->getX() <<","<< posit->getY() << "," << posit->getSpeed() << std::endl; - err_solved_log.close(); - } - } else if (uwAUVh->error() >= 1 ){ alarm_mode = 2; if (debug_) - std::cout << NOW << " UwAUVErrModule::recv(Packet *p) for SURE there is an error ("<< x_e <<","<< y_e <<") solved " + std::cout << NOW << " UwAUVErrModule::recv(Packet *p) for SURE there is an error ("<< x_e <<","<< y_e <<")" "STOP until ctr arrival"<< std::endl; }else{ @@ -382,7 +403,7 @@ void UwAUVErrorModule::recv(Packet* p) { alarm_mode = 1; if (debug_) - std::cout << NOW << " UwAUVErrModule::recv(Packet *p) MAYBE there is an error ("<< x_e <<","<< y_e <<") solved " + std::cout << NOW << " UwAUVErrModule::recv(Packet *p) MAYBE there is an error ("<< x_e <<","<< y_e <<")"<< "continue tx"<< std::endl; } @@ -407,7 +428,7 @@ void UwAUVErrorModule::recv(Packet* p) { <<"received"<< std::endl; if (log_flag == 1) { - out_file_stats.open("postion_log_a.csv",std::ios_base::app); + out_file_stats.open("log/position_log_a.csv",std::ios_base::app); out_file_stats << NOW << "," << posit->getX() << ","<< posit->getY() << "," << posit->getZ() << std::endl; out_file_stats.close(); @@ -415,7 +436,7 @@ void UwAUVErrorModule::recv(Packet* p) { } -double UwAUVErrorModule::getErrorProb(){ +double UwAUVErrorModule::getErrorMeasure(){ std::random_device rd; std::mt19937 gen(rd()); @@ -439,17 +460,33 @@ double UwAUVErrorModule::getErrorProb(){ //double th_5sig = std::erfc((5*sigma) / std::sqrt(2)) / 2; - if (p_e >= 0.001){ //if p_e is small enough --> no error, otherwise gray zone + if (p_e >= accuracy){ //if p_e is small enough --> no error, otherwise gray zone alarm_mode = 1; } + if (t_e > th_ne){ + if (log_flag == 1) { + t_err_log.open("log/true_error_log.csv",std::ios_base::app); + t_err_log << NOW << "," << x_e <<","<< y_e <<","<< 1 << std::endl; + t_err_log.close(); + } + }else{ + if (log_flag == 1) { + t_err_log.open("log/true_error_log.csv",std::ios_base::app); + t_err_log << NOW << "," << x_e <<","<< y_e <<","<< 0 << std::endl; + t_err_log.close(); + } + } + + + return m; } -double UwAUVErrorModule::getErrorProb(double t_e){ +double UwAUVErrorModule::getErrorMeasure(double t_e){ std::random_device rd; std::mt19937 gen(rd()); diff --git a/DESERT_Addons/uwauv/uwauverror-module.h b/DESERT_Addons/uwauv/uwauverror-module.h index 3191f43e..190812d0 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.h +++ b/DESERT_Addons/uwauv/uwauverror-module.h @@ -206,21 +206,22 @@ class UwAUVErrorModule : public UwCbrModule { int period; std::ofstream out_file_stats; /**< Output stream for the textual file of debug */ std::ofstream err_log; - std::ofstream err_solved_log; + std::ofstream t_err_log; float x_e; float y_e; - float error_p; + float error_m; int alarm_mode; private: double speed; - virtual double getErrorProb(); - virtual double getErrorProb(double t_e); + virtual double getErrorMeasure(); + virtual double getErrorMeasure(double t_e); //virtual double QFunction(double x); double t_e; // True error in that point double sigma; // standard deviation double th_ne; // if x < th_e NO error + double accuracy; }; From 9e7817e1de2b27ef3de533cc6d5667a641986d45 Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Mon, 3 Jul 2023 14:47:24 +0200 Subject: [PATCH 14/36] uwsme correction --- DESERT_Addons/uwauv/Makefile.am | 2 +- .../mobility/uwsmeposition/uwsmeposition.cpp | 217 +++++++++++++++--- .../mobility/uwsmeposition/uwsmeposition.h | 3 +- 3 files changed, 192 insertions(+), 30 deletions(-) diff --git a/DESERT_Addons/uwauv/Makefile.am b/DESERT_Addons/uwauv/Makefile.am index aac19869..16c03384 100644 --- a/DESERT_Addons/uwauv/Makefile.am +++ b/DESERT_Addons/uwauv/Makefile.am @@ -31,7 +31,7 @@ AM_CXXFLAGS = -Wall -ggdb3 lib_LTLIBRARIES = libuwauv.la -libuwauv_la_SOURCES = uwauv-module.cc uwauverror-module.cc uwauv-module.h uwauverror-module.h uwauv-packet.h uwauvctr-module.cc uwauvctrer-module.cc uwauvctr-module.h uwauvctrer-module.h initlib.cc +libuwauv_la_SOURCES = uwauv-module.cc uwauv-module.h uwauverror-module.cc uwauverror-module.h uwauverror-b-module.cc uwauverror-b-module.h uwauv-packet.h uwauvctr-module.cc uwauvctr-module.h uwauvctrer-module.cc uwauvctrer-module.h uwauvctrer-b-module.cc uwauvctrer-b-module.h initlib.cc libuwauv_la_CPPFLAGS = @NS_CPPFLAGS@ @NSMIRACLE_CPPFLAGS@ @DESERT_CPPFLAGS@ libuwauv_la_LDFLAGS = @NS_LDFLAGS@ @NSMIRACLE_LDFLAGS@ @DESERT_LDFLAGS@ @DESERT_LDFLAGS_BUILD@ diff --git a/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.cpp b/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.cpp index 14888e38..3ac8dfc3 100644 --- a/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.cpp +++ b/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.cpp @@ -61,6 +61,7 @@ static class UWSMEPositionClass : public TclClass UWSMEPosition::UWSMEPosition() : UWSMPosition() , alarm_mode(false) + , exist(false) { bind("debug_", &debug_); } @@ -127,6 +128,45 @@ UWSMEPosition::setdest( z_dest); }else{ + if (!waypoints.empty()){ + + if (waypoints[0][0] == x_dest && waypoints[0][1] == y_dest && waypoints[0][2] == z_dest){ + + if (debug_) + printf("New dest next waypoint in the queue (%f,%f,%f)\n", + waypoints[0][0], + waypoints[0][1], + waypoints[0][2]); + + }else{ + + waypoints.insert(waypoints.begin(),{x_dest,y_dest,z_dest,speed_setted}); + if (debug_) + printf("New destionation (%f,%f,%f), skip the queue\n", + x_dest, + y_dest, + z_dest); + + } + + }else{ + + waypoints.push_back({x_dest,y_dest,z_dest,speed_setted}); + } + + if (debug_) + printf("Pos (%f,%f,%f), last dest(%f,%f,%f), new dest = (%f,%f,%f)\n", + x_, + y_, + z_, + Xdest_, + Ydest_, + Zdest_, + x_dest, + y_dest, + z_dest); + + UWSMPosition::setdest(x_dest,y_dest,z_dest,speed_setted); if (debug_) @@ -147,7 +187,6 @@ void UWSMEPosition::setdest(double x_dest, double y_dest, double z_dest) { if (alarm_mode){ - if (debug_) printf("Alarm_mode %f, dest(%f,%f,%f) not accepted\n", alarm_mode, @@ -156,8 +195,35 @@ UWSMEPosition::setdest(double x_dest, double y_dest, double z_dest) z_dest); }else{ + if (!waypoints.empty()){ + if (waypoints[0][0] == x_dest && waypoints[0][1] == y_dest && waypoints[0][2] == z_dest){ + + if (debug_) + printf("New dest next waypoint in the queue (%f,%f,%f)\n", + waypoints[0][0], + waypoints[0][1], + waypoints[0][2]); + + }else{ + + waypoints.insert(waypoints.begin(),{x_dest,y_dest,z_dest}); + if (debug_) + printf("New destionation (%f,%f,%f), skip the queue\n", + x_dest, + y_dest, + z_dest); + + } + + }else{ + + waypoints.push_back({x_dest,y_dest,z_dest}); + } + + UWSMPosition::setdest(x_dest,y_dest,z_dest); + if (debug_) printf("Pos (%f,%f,%f), new dest(%f,%f,%f)\n", x_, @@ -175,17 +241,29 @@ UWSMEPosition::adddest( { if (!waypoints.empty()){ - waypoints.push_back({x_dest,y_dest,z_dest, speed_setted}); + exist = false; - if (debug_) - printf("New waypoint (%f,%f,%f)\n", - x_dest, - y_dest, - z_dest); + 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_) + printf("New waypoint (%f,%f,%f)\n", + x_dest, + y_dest, + z_dest); + } + }else{ + //waypoints.push_back({x_dest,y_dest,z_dest, speed_setted}); UWSMEPosition::setdest(x_dest,y_dest,z_dest, speed_setted); - if (debug_) printf("Pos (%f,%f,%f), new dest(%f,%f,%f)\n", x_, @@ -196,6 +274,7 @@ UWSMEPosition::adddest( Zdest_); } + //waypoints.push_back({x_dest,y_dest,z_dest, speed_setted}); /*if (!waypoints.empty()){ @@ -239,15 +318,29 @@ UWSMEPosition::adddest( if (!waypoints.empty()){ - waypoints.push_back({x_dest,y_dest,z_dest}); + exist = false; - if (debug_) - printf("New waypoint (%f,%f,%f)\n", - x_dest, - y_dest, - z_dest); + 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}); + if (debug_) + printf("New waypoint (%f,%f,%f)\n", + x_dest, + y_dest, + z_dest); + } + }else{ + + //waypoints.push_back({x_dest,y_dest,z_dest}); UWSMEPosition::setdest(x_dest,y_dest,z_dest); if (debug_) @@ -260,6 +353,8 @@ UWSMEPosition::adddest( Zdest_); } + //waypoints.push_back({x_dest,y_dest,z_dest}); + /*if (!waypoints.empty()){ waypoints.push_back({x_dest,y_dest,z_dest}); @@ -308,23 +403,39 @@ UWSMEPosition::update(double now) y_ = Ysorg_; z_ = Zsorg_; + if (!waypoints.empty()){ - if(waypoints[0].size()>3){ - UWSMEPosition::setdest(waypoints[0][0],waypoints[0][1],waypoints[0][2],waypoints[0][3]); - }else{ - UWSMEPosition::setdest(waypoints[0][0],waypoints[0][1],waypoints[0][2]); - } + if(waypoints[0][0] == Xdest_ && waypoints[0][1] == Ydest_ && waypoints[0][2] == Zdest_){ + + if (debug_) + printf("Last waypoints erased (%f,%f,%f)\n", + waypoints[0][0], + waypoints[0][1], + waypoints[0][2]); - waypoints.erase(waypoints.begin()); + waypoints.erase(waypoints.begin()); - if (debug_) - printf("New dest (%f,%f,%f) from waypoints list\n", - Xdest_, - Ydest_, - Zdest_); + if (!waypoints.empty()){ + + if(waypoints[0].size()>3){ + UWSMEPosition::setdest(waypoints[0][0],waypoints[0][1],waypoints[0][2],waypoints[0][3]); + }else{ + UWSMEPosition::setdest(waypoints[0][0],waypoints[0][1],waypoints[0][2]); + } + + if (debug_) + printf("New dest (%f,%f,%f) from waypoints list\n", + Xdest_, + Ydest_, + Zdest_); + } + } + } + + } else { theta = acos((Zdest_ - Zsorg_) / theta_den); @@ -352,8 +463,60 @@ UWSMEPosition::update(double now) y_ = Ydest_; z_ = Zdest_; + + if (debug_) + printf("Destination (%f,%f,%f) reached\n", + Xdest_, + Ydest_, + Zdest_); + if (!waypoints.empty()){ + if(waypoints[0][0] == Xdest_ && waypoints[0][1] == Ydest_ && waypoints[0][2] == Zdest_){ + + if (debug_) + printf("Last waypoints erased (%f,%f,%f)\n", + waypoints[0][0], + waypoints[0][1], + waypoints[0][2]); + + waypoints.erase(waypoints.begin()); + + + if (!waypoints.empty()){ + + if (debug_) + printf("Next dest (%f,%f,%f)\n", + waypoints[0][0], + waypoints[0][1], + waypoints[0][2]); + + if(waypoints[0].size()>3){ + UWSMEPosition::setdest(waypoints[0][0],waypoints[0][1],waypoints[0][2],waypoints[0][3]); + }else{ + UWSMEPosition::setdest(waypoints[0][0],waypoints[0][1],waypoints[0][2]); + } + + if (debug_) + printf("New dest (%f,%f,%f) from waypoints list\n", + Xdest_, + Ydest_, + Zdest_); + } + } + + } + + + + /*if (!waypoints.empty()){ + + if (debug_) + printf("New destination (%f,%f,%f) setted\n", + waypoints[0][0], + waypoints[0][1], + waypoints[0][2]); + if(waypoints[0].size()>3){ UWSMEPosition::setdest(waypoints[0][0],waypoints[0][1],waypoints[0][2],waypoints[0][3]); @@ -363,14 +526,12 @@ UWSMEPosition::update(double now) UWSMEPosition::setdest(waypoints[0][0],waypoints[0][1],waypoints[0][2]); } - waypoints.erase(waypoints.begin()); - if (debug_) printf("New dest (%f,%f,%f) from waypoints list\n", Xdest_, Ydest_, Zdest_); - } + }*/ } if (debug_) diff --git a/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.h b/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.h index 2d81b720..ed04b603 100644 --- a/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.h +++ b/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.h @@ -133,7 +133,8 @@ class UWSMEPosition : public UWSMPosition std::vector> waypoints; int debug_; - bool alarm_mode; //alarm_mode true block all the application from updating the destination + bool alarm_mode; //alarm_mode true block all the application from updating the destination + bool exist; }; From 38a9ecb3b5d1f2721449adb3c9cd08fbc7f2483a Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Mon, 3 Jul 2023 14:47:53 +0200 Subject: [PATCH 15/36] simulation correction --- .../DESERT/samples/desert_samples/AUV/asv.tcl | 19 +- .../samples/desert_samples/AUV/asv_basic.tcl | 164 ++++++ .../DESERT/samples/desert_samples/AUV/auv.tcl | 32 +- .../samples/desert_samples/AUV/auv_basic.tcl | 155 +++++ .../desert_samples/AUV/test_uwauv_error.tcl | 551 ++++++++++++++++++ ...fic_auv.tcl => test_uwauv_error_basic.tcl} | 151 ++--- 6 files changed, 926 insertions(+), 146 deletions(-) create mode 100644 DESERT_Framework/DESERT/samples/desert_samples/AUV/asv_basic.tcl create mode 100644 DESERT_Framework/DESERT/samples/desert_samples/AUV/auv_basic.tcl create mode 100644 DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwauv_error.tcl rename DESERT_Framework/DESERT/samples/desert_samples/AUV/{test_uwmulti_traffic_auv.tcl => test_uwauv_error_basic.tcl} (79%) diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl index fcfaf39a..5b5c7092 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl @@ -12,9 +12,9 @@ proc createASV { id } { # TRAFFICO 2: CONTROL: ASV --> AUV Module/UW/AUV/CTR set packetSize_ $opt(pktsize) Module/UW/AUV/CTR set period_ $opt(ctr_period) - Module/UW/AUV/CTR set PoissonTraffic_ 1 - Module/UW/AUV/CTR set traffic_type_ 2 - Module/UW/AUV/CTR set debug_ 0 + 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] @@ -22,13 +22,14 @@ proc createASV { id } { # TRAFFICO 3: ERROR: AUV --> ASV Module/UW/AUV/CER set packetSize_ $opt(pktsize) - Module/UW/AUV/CER set period_ 500 - Module/UW/AUV/CER set PoissonTraffic_ 1 - Module/UW/AUV/CER set traffic_type_ 3 - Module/UW/AUV/CER set debug_ 1 + Module/UW/AUV/CER set period_ 60 + 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_flag_ 1 - Module/UW/AUV/CER set sigma_ 0.01 - Module/UW/AUV/CER set th_ne_ 0.99 + 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) for {set id1 0} {$id1 <= $opt(n_auv)} {incr id1} { 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..53cbf7da --- /dev/null +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv_basic.tcl @@ -0,0 +1,164 @@ +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_ $opt(ctr_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: AUV --> ASV + Module/UW/AUV/CEB set packetSize_ $opt(pktsize) + Module/UW/AUV/CEB set period_ 60 + Module/UW/AUV/CEB set PoissonTraffic_ 0 + Module/UW/AUV/CEB set traffic_type_ 3 + Module/UW/AUV/CEB set debug_ 0 + Module/UW/AUV/CEB set log_flag_ 1 + Module/UW/AUV/CEB set errorp_ 0.01 + + + for {set id1 0} {$id1 <= $opt(n_auv)} {incr id1} { + set asv_err($id1) [new Module/UW/AUV/CEB] + } + + set udp_asv [new Module/UW/UDP] + set ipr_asv [new Module/UW/StaticRouting] + set ipif_asv [new Module/UW/IP] + + 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 index 31d75cf1..a81e389c 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl @@ -9,29 +9,22 @@ proc createAUV { id } { 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(auv_period) - Module/UW/AUV set PoissonTraffic_ 1 - Module/UW/AUV set traffic_type_ 1 - Module/UW/AUV set debug_ 0 + 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 2: CONTROL:ASV --> AUV - #Module/UW/ROV/CTR set packetSize_ $opt(pktsize_control) - #Module/UW/ROV/CTR set period_ $opt(cbr_period_control) - #Module/UW/ROV/CTR set PoissonTraffic_ 1 - #Module/UW/ROV/CTR set traffic_type_ 2 - # Module/UW/CBR set debug_ 0 - #set cbr2_auv($id) [new Module/UW/ROV/CTR] - # 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_ 500 - Module/UW/AUV/ERR set PoissonTraffic_ 1 + Module/UW/AUV/ERR set period_ 60 + Module/UW/AUV/ERR set PoissonTraffic_ 0 Module/UW/AUV/ERR set traffic_type_ 3 - Module/UW/AUV/ERR set debug_ 1 + Module/UW/AUV/ERR set debug_ 0 Module/UW/AUV/ERR set log_flag_ 1 - Module/UW/AUV/ERR set sigma_ 0.01 - Module/UW/AUV/ERR set th_ne_ 0.99 + 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] @@ -44,13 +37,6 @@ proc createAUV { id } { set ctr_auv($id) [new Module/UW/MULTI_TRAFFIC_RANGE_CTR] - #Module/UW/TDMA set frame_duration $opt(tdma_frame) - #Module/UW/TDMA set fair_mode 1 - #Module/UW/TDMA set guard_time $opt(tdma_gard) - #Module/UW/TDMA set tot_slots $opt(n_auv) - #Module/UW/TDMA set debug_ 0 - #Module/UW/TDMA set queue_size_ 100 - 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 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..50e67310 --- /dev/null +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv_basic.tcl @@ -0,0 +1,155 @@ +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 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(auv_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/ERB set packetSize_ $opt(pktsize) + Module/UW/AUV/ERB set period_ 60 + Module/UW/AUV/ERB set PoissonTraffic_ 0 + Module/UW/AUV/ERB set traffic_type_ 3 + Module/UW/AUV/ERB set debug_ 0 + Module/UW/AUV/ERB set log_flag_ 1 + Module/UW/AUV/ERB set errrop_ 0.01 + + set auv_err($id) [new Module/UW/AUV/ERB] + + + 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] + 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 $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/test_uwauv_error.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwauv_error.tcl new file mode 100644 index 00000000..ff245189 --- /dev/null +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwauv_error.tcl @@ -0,0 +1,551 @@ +# +# 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: Giovanni Toso +# 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 depicts a very simple but complete stack in which two node_leaders send data +# to a common sink. The second node_leader is used by the first one as a relay to send data to the sink. +# The routes are configured by using UW/STATICROUTING. +# The application used to generate data is UW/CBR. +# ---------------------------------------------------------------------------------- +# Stack +# Node 1 Node 2 Sink +# +--------------------------+ +--------------------------+ +-------------+------------+ +# | 7. UW/CBR | | 7. UW/CBR | | 7. UW/CBR | UW/CBR | +# +--------------------------+ +--------------------------+ +-------------+------------+ +# | 6. UW/UDP | | 6. UW/UDP | | 6. UW/UDP | +# +--------------------------+ +--------------------------+ +--------------------------+ +# | 5. UW/STATICROUTING | | 5. UW/STATICROUTING | | 5. UW/STATICROUTING | +# +--------------------------+ +--------------------------+ +--------------------------+ +# | 4. UW/IP | | 4. UW/IP | | 4. UW/IP | +# +--------------------------+ +--------------------------+ +--------------------------+ +# | 3. UW/MLL | | 3. UW/MLL | | 3. UW/MLL | +# +--------------------------+ +--------------------------+ +--------------------------+ +# | 2. UW/CSMA_ALOHA | | 2. UW/CSMA_ALOHA | | 2. UW/CSMA_ALOHA | +# +--------------------------+ +--------------------------+ +--------------------------+ +# | 1. Module/MPhy/BPSK | | 1. Module/MPhy/BPSK | | 1. Module/MPhy/BPSK | +# +--------------------------+ +--------------------------+ +--------------------------+ +# | | | | | | +# +----------------------------------------------------------------------------------------+ +# | 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 libuwsmeposition.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 libuwnoderep.so; #non riesco ad importarla +#load libuwsecurity_clmsg.so; #non riesco ad importarla +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) 2 ;# Number of Nodes +set opt(starttime) 1 +set opt(stoptime) 15000 +set opt(txduration) [expr $opt(stoptime) - $opt(starttime)] +set opt(rngstream) 1 + +set opt(maxinterval_) 20.0 +set opt(freq) 25000.0 +set opt(bw) 5000.0 +#set opt(freq_hf) 60000.0 +#set opt(bw_hf) 10000.0 +set opt(bitrate) 4800.0 +#set opt(bitrate_hf) 64000.0 +set opt(ack_mode) "setNoAckMode" + + +set opt(txpower) 135.0 +#set opt(txpower_hf) 135.0 + +#set opt(tdma_frame) 20 +#set opt(tdma_gard) 1 + +set opt(pktsize) 125 +set opt(ctr_period) 60 + +set opt(pktsize_monitoring) 125 +set opt(auv_period) 60 + +#set opt(pktsize_control) 100 +#set opt(cbr_period_control) [expr $opt(cbr_period_monitoring)*4] + +set opt(pktsize_error) 100 +set opt(auv_period_error) 60 + +set opt(op_freq) 10000000 +set opt(op_bw) 100000 +set opt(bitrate_op) 1000000 +set opt(txpower_op) 30 +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 +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] +set propagation [new MPropagation/Underwater] +set data_mask [new MSpectralMask/Rect] +$data_mask setFreq $opt(freq) +$data_mask setBandwidth $opt(bw) + +######################### +# Module Configuration # +######################### +#UW/AUV +Module/UW/AUV set packetSize_ $opt(pktsize) +Module/UW/AUV set period_ $opt(auv_period) +Module/UW/AUV set PoissonTraffic_ 1 +Module/UW/AUV set debug_ 0 + +# BPSK +Module/MPhy/BPSK set BitRate_ $opt(bitrate) +Module/MPhy/BPSK set TxPower_ $opt(txpower) + +#FLOODING +Module/UW/FLOODING set ttl_ 2 +Module/UW/FLOODING set maximum_cache_time__time_ $opt(stoptime) + + +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.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/UWSME debug_ 1 + +# Setup positions +set position_asv [new "Position/UWSME"] +$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/UWSME debug_ 1 + + set position_auv($id) [new "Position/UWSME"] + $position_auv($id) setX_ 0 + $position_auv($id) setY_ 0 + $position_auv($id) setZ_ -1000 + + $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" + 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 + + + puts "---------------------------------------------------------------------" + #puts "Simulation summary" + #puts "Leader addr = [$ipif_asv addr]" + #for {set i 0} {$i < $opt(n_auv)} {incr i} { + # puts "Diver addr = [$ipif_auv($i) addr]" + # #puts "Packets in buffer [$mac_auv($i) get_buffer_size]" + #} + #puts "number of divers : $opt(n_auv)" + #puts "simulation length: $opt(txduration) s" + #puts "---------------------------------------------------------------------" + + set sum_cbr_throughput 0 + set sum_cbr_sent_pkts 0.0 + set sum_cbr_rcv_pkts 0.0 + + set sum_cbr_throughput2 0 + set sum_cbr_sent_pkts2 0.0 + set sum_cbr_rcv_pkts2 0.0 + + set sum_cbr_throughput3 0 + set sum_cbr_sent_pkts3 0.0 + set sum_cbr_rcv_pkts3 0.0 + + set sum_cbr_throughput4 0 + set sum_cbr_sent_pkts4 0.0 + set sum_cbr_rcv_pkts4 0.0 + + + for {set i 0} {$i < $opt(n_auv)} {incr i} { + set cbr_throughput [$asv_app($i) getthr] + set cbr_sent_pkts [$auv_app($i) getsentpkts] + set cbr_rcv_pkts [$asv_app($i) getrecvpkts] + + set cbr_throughput2 [$auv_app($i) getthr] + set cbr_sent_pkts2 [$asv_app($i) getsentpkts] + set cbr_rcv_pkts2 [$auv_app($i) getrecvpkts] + + set cbr_throughput4 [$asv_err($i) getthr] + set cbr_sent_pkts4 [$auv_err($i) getsentpkts] + set cbr_rcv_pkts4 [$asv_err($i) getrecvpkts] + + set sum_cbr_throughput [expr $sum_cbr_throughput + $cbr_throughput] + set sum_cbr_sent_pkts [expr $sum_cbr_sent_pkts + $cbr_sent_pkts] + set sum_cbr_rcv_pkts [expr $sum_cbr_rcv_pkts + $cbr_rcv_pkts] + + set sum_cbr_throughput2 [expr $sum_cbr_throughput2 + $cbr_throughput2] + set sum_cbr_sent_pkts2 [expr $sum_cbr_sent_pkts2 + $cbr_sent_pkts2] + set sum_cbr_rcv_pkts2 [expr $sum_cbr_rcv_pkts2 + $cbr_rcv_pkts2] + + set sum_cbr_throughput4 [expr $sum_cbr_throughput4 + $cbr_throughput4] + set sum_cbr_sent_pkts4 [expr $sum_cbr_sent_pkts4 + $cbr_sent_pkts4] + set sum_cbr_rcv_pkts4 [expr $sum_cbr_rcv_pkts4 + $cbr_rcv_pkts4] + } + + set ipheadersize [$ipif_asv getipheadersize] + set udpheadersize [$udp_asv getudpheadersize] + set cbrheadersize [$asv_app(0) getcbrheadersize] + + + #puts "IP Pkt Header Size : $ipheadersize" + #puts "UDP Header Size : $udpheadersize" + #puts "CBR Header Size : $cbrheadersize" + + #puts "Traffic MONITORING ---------------------------------------------" + #puts "Mean Throughput : [expr ($sum_cbr_throughput/(1+$opt(n_auv)))]" + #puts "Sent Packets : $sum_cbr_sent_pkts" + #puts "Received Packets : $sum_cbr_rcv_pkts" + #puts "Packet Delivery Ratio : [expr $sum_cbr_rcv_pkts / $sum_cbr_sent_pkts * 100]" + + #puts "Traffic CONTROL ---------------------------------------------" + #puts "Mean Throughput : [expr ($sum_cbr_throughput2/($opt(n_auv)))]" + #puts "Sent Packets : $sum_cbr_sent_pkts2" + #puts "Received Packets : $sum_cbr_rcv_pkts2" + #puts "Packet Delivery Ratio : [expr $sum_cbr_rcv_pkts2 / $sum_cbr_sent_pkts2 * 100]" + + #puts "Traffic ERROR ---------------------------------------------" + #puts "Mean Throughput : [expr ($sum_cbr_throughput4/($opt(n_auv)))]" + #puts "Sent Packets : $sum_cbr_sent_pkts4" + #puts "Received Packets : $sum_cbr_rcv_pkts4" + #puts "Packet Delivery Ratio : [expr $sum_cbr_rcv_pkts4 / $sum_cbr_sent_pkts4 * 100]" + + $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_uwmulti_traffic_auv.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwauv_error_basic.tcl similarity index 79% rename from DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl rename to DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwauv_error_basic.tcl index ec0dcbae..32f1311c 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwmulti_traffic_auv.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwauv_error_basic.tcl @@ -125,11 +125,11 @@ $ns use-Miracle ################## # Tcl variables # ################## -set opt(n_auv) 2 ;# Number of Nodes +set opt(n_auv) 2 ;# Number of Nodes set opt(starttime) 1 set opt(stoptime) 15000 set opt(txduration) [expr $opt(stoptime) - $opt(starttime)] -set opt(rngstream) 1 +set opt(rngstream) 3 set opt(maxinterval_) 20.0 set opt(freq) 25000.0 @@ -174,26 +174,34 @@ 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(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 != 2} { + if {$argc != 4} { puts "The script requires two inputs:" - puts "- the first for the Poisson CBR period" - puts "- the second for the rngstream" - puts "example: ns test_uw_rov.tcl 60 13" + 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(ctr_period) [lindex $argv 0] - set opt(rngstream) [lindex $argv 1]; + 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.csv" +set opt(waypoint_file) "../dbs/wp_path/rov_path_square.csv" #random generator global defaultRNG @@ -219,10 +227,6 @@ set data_mask [new MSpectralMask/Rect] $data_mask setFreq $opt(freq) $data_mask setBandwidth $opt(bw) -#set data_mask_hf [new MSpectralMask/Rect] -#$data_mask_hf setFreq $opt(freq_hf) -#$data_mask_hf setBandwidth $opt(bw_hf) - ######################### # Module Configuration # ######################### @@ -232,19 +236,6 @@ Module/UW/AUV set period_ $opt(auv_period) Module/UW/AUV set PoissonTraffic_ 1 Module/UW/AUV set debug_ 0 -#UW/AUV/ERR -#Module/UW/AUV/ERR set packetSize_ $opt(pktsize) -#Module/UW/AUV/ERR set period_ $opt(auv_period) -#Module/UW/AUV/ERR set PoissonTraffic_ 1 -#Module/UW/AUV/ERR set debug_ 0 - -#UW/AUV/CERR -#Module/UW/AUV/CER set packetSize_ $opt(pktsize) -#Module/UW/AUV/CER set period_ $opt(auv_period) -#Module/UW/AUV/CER set PoissonTraffic_ 1 -#Module/UW/AUV/CER set debug_ 1 - - # BPSK Module/MPhy/BPSK set BitRate_ $opt(bitrate) Module/MPhy/BPSK set TxPower_ $opt(txpower) @@ -264,11 +255,6 @@ 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 -#Module/UW/TDMA set frame_duration $opt(tdma_frame) -#Module/UW/TDMA set fair_mode 1 -#Module/UW/TDMA set guard_time $opt(tdma_gard) -#Module/UW/TDMA set tot_slots $opt(n_auv) - # PHY Module/UW/PHYSICAL set BitRate_ $opt(bitrate) @@ -303,6 +289,7 @@ 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] @@ -314,14 +301,13 @@ $data_mask_op setBandwidth $opt(op_bw) # Procedure(s) to create node_leaders # ################################ -source "auv.tcl" -source "asv.tcl" +source "auv_basic.tcl" +source "asv_basic.tcl" for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { createAUV $id1 } createASV $opt(n_auv) -#createROV [expr $opt(n_auv) + 1] ################################ # Inter-node_leader module connection # @@ -348,55 +334,35 @@ proc connectNodes {id1} { # Setup flows for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { - #for {set id2 0} {$id2 < $opt(n_auv)} {incr id2} { - # if {$id1 != $id2} { - connectNodes $id1 - # } - #} + connectNodes $id1 } # Fill ARP tables for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { - #for {set id2 0} {$id2 < $opt(n_auv)} {incr id2} { - # $mll_auv($id1) addentry [$ipif_auv($id2) addr] [$mac_auv($id2) addr] - # $mll_op_auv($id1) addentry [$ipif_auv($id2) addr] [$mac_op_auv($id2) addr] - #} + $mll_auv($id1) addentry [$ipif_asv addr] [$mac_asv addr] - # $mll_diver($id1) addentry [$ipif_rov addr] [$mac_rov addr] $mll_op_auv($id1) addentry [$ipif_asv addr] [$mac_op_asv addr] - # $mll_hf_diver($id1) addentry [$ipif_rov addr] [$mac_rov 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] } -#$mll_asv addentry [$ipif_rov addr] [$mac_rov addr] -#$mll_op_asv addentry [$ipif_rov addr] [$mac_op_rov addr] - -#$mll_rov addentry [$ipif_leader addr] [$mac_leader addr] -#$mll_op_rov addentry [$ipif_leader addr] [$mac_op_leader addr] Position/UWSME debug_ 1 + # Setup positions set position_asv [new "Position/UWSME"] $position_asv setX_ 0 $position_asv setY_ 0 $position_asv setZ_ -1 -#$position_rov setX_ 0 -#$position_rov setY_ 10 -#$position_rov setZ_ -1000 - for {set id 0} {$id < $opt(n_auv)} {incr id} { - #$cbr_asv($id) setPosition $position_asv $asv_app($id) setPosition $position_asv $asv_err($id) setPosition $position_asv Position/UWSME debug_ 1 set position_auv($id) [new "Position/UWSME"] - #$position_auv($id) setX_ [expr -50 * (1 + $id % $opt(n_auv)/2) - 25 + 50 * rand()] $position_auv($id) setX_ 0 - #$position_auv($id) setY_ [expr -50 + 100 * ($id%2) - 25 + 50 * rand()] $position_auv($id) setY_ 0 $position_auv($id) setZ_ -1000 @@ -411,12 +377,7 @@ for {set id 0} {$id < $opt(n_auv)} {incr id} { 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] - - # $ipr2_diver($id) addRoute [$ipif2_rov addr] [$ipif2_leader addr] - # $ipr2_leader addRoute [$ipif2_diver($id) addr] [$ipif2_diver($id) addr] } -#$ipr_leader addRoute [$ipif_rov addr] [$ipif_rov addr] - ##################### # Start/Stop Timers # @@ -433,52 +394,38 @@ foreach line $data { if {[regexp {^(.*),(.*),(.*),(.*)$} $line -> t x y z]} { $ns at $t "update_and_check $t" 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]" + $ns at $t "$asv_app($id) sendPosition [expr $x*($id*(2))-$x] [expr $y*($id*(-2))+$y] [expr $z]" } } } - -#$ns at $opt(starttime) "$cbr3_asv($opt(n_auv)) start" -#$ns at $opt(stoptime) "$cbr3_asv($opt(n_auv)) stop" +set min 0 +set max 100 for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { - #$ns at $opt(starttime) "$cbr_asv($id1) start" - #$ns at $opt(stoptime) "$cbr_asv($id1) stop" - $ns at $opt(starttime) "$asv_app($id1) start" + 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 $opt(starttime) "$auv_app($id1) start" + $ns at [expr $opt(starttime) + [$time_ value]] "$auv_app($id1) start" $ns at $opt(stoptime) "$auv_app($id1) stop" - $ns at $opt(starttime) "$auv_err($id1) start" + $ns at [expr $opt(starttime) + [$time_ value]] "$auv_err($id1) start" $ns at $opt(stoptime) "$auv_err($id1) stop" - $ns at $opt(starttime) "$asv_err($id1) start" + $ns at [expr $opt(starttime) + [$time_ value]] "$asv_err($id1) start" $ns at $opt(stoptime) "$asv_err($id1) stop" - - #$ns at $opt(starttime) "$cbr3_auv($id1) start" - #$ns at $opt(stoptime) "$cbr3_auv($id1) stop" - - #$ns at $opt(starttime) "$mac_auv($id1) start" - #$ns at $opt(stoptime) "$mac_auv($id1) stop" - - #$ns at $opt(starttime) "$mac_op_auv($id1) start" - #$ns at $opt(stoptime) "$mac_op_auv($id1) stop" - } -#$ns at $opt(starttime) "$mac_asv start" -#$ns at $opt(stoptime) "$mac_asv stop" - -#$ns at $opt(starttime) "$mac_op_asv start" -#$ns at $opt(stoptime) "$mac_op_asv 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_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} { @@ -553,10 +500,6 @@ proc finish {} { set cbr_sent_pkts4 [$auv_err($i) getsentpkts] set cbr_rcv_pkts4 [$asv_err($i) getrecvpkts] - #set cbr_throughput3 [$cbr3_asv($i) getthr] - #set cbr_sent_pkts3 [$cbr3_auv($i) getsentpkts] - #set cbr_rcv_pkts3 [$cbr3_asv($i) getrecvpkts] - set sum_cbr_throughput [expr $sum_cbr_throughput + $cbr_throughput] set sum_cbr_sent_pkts [expr $sum_cbr_sent_pkts + $cbr_sent_pkts] set sum_cbr_rcv_pkts [expr $sum_cbr_rcv_pkts + $cbr_rcv_pkts] @@ -570,19 +513,6 @@ proc finish {} { set sum_cbr_rcv_pkts4 [expr $sum_cbr_rcv_pkts4 + $cbr_rcv_pkts4] } - #set sum_cbr_sent_pkts [expr $sum_cbr_sent_pkts + [$cbr_asv($opt(n_auv)) getsentpkts]] - #set sum_cbr_sent_pkts3 [expr $sum_cbr_sent_pkts3 + [$cbr3_asv getsentpkts]] - - #set sum_cbr_rcv_pkts [expr $sum_cbr_rcv_pkts + [$cbr_asv($opt(n_auv)) getrecvpkts]] - #set sum_cbr_rcv_pkts3 [expr $sum_cbr_rcv_pkts3 + [$cbr3_asv($opt(n_auv)) getrecvpkts]] - - #set sum_cbr_throughput [expr $sum_cbr_throughput + [$cbr_asv($opt(n_auv)) getthr]] - #set sum_cbr_throughput3 [expr $sum_cbr_throughput3 + [$cbr3_asv($opt(n_auv)) getthr]] - - #set sum_cbr_throughput2 [expr [$cbr2_asv(0) getthr] + $sum_cbr_throughput2] - #set sum_cbr_rcv_pkts2 [expr [$cbr2_asv(0) getrecvpkts] + $sum_cbr_rcv_pkts2] - #set sum_cbr_sent_pkts2 [expr $sum_cbr_sent_pkts2 + [$cbr2_asv($opt(n_auv)) getsentpkts]] - set ipheadersize [$ipif_asv getipheadersize] set udpheadersize [$udp_asv getudpheadersize] set cbrheadersize [$asv_app(0) getcbrheadersize] @@ -610,13 +540,6 @@ proc finish {} { puts "Received Packets : $sum_cbr_rcv_pkts4" puts "Packet Delivery Ratio : [expr $sum_cbr_rcv_pkts4 / $sum_cbr_sent_pkts4 * 100]" - - #puts "Traffic 3 ---------------------------------------------" - #puts "Mean Throughput : [expr ($sum_cbr_throughput3/(1+$opt(n_diver)))]" - #puts "Sent Packets : $sum_cbr_sent_pkts3" - #puts "Received Packets : $sum_cbr_rcv_pkts3" - #puts "Packet Delivery Ratio : [expr $sum_cbr_rcv_pkts3 / $sum_cbr_sent_pkts3 * 100]" - $ns flush-trace close $opt(tracefile) } From e20ac565ed180b340b2012d3b34c6ef4fbcd2ac4 Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Fri, 7 Jul 2023 13:38:02 +0200 Subject: [PATCH 16/36] log msg fixed --- DESERT_Addons/uwauv/uwauvctrer-b-module.cc | 14 +++- DESERT_Addons/uwauv/uwauvctrer-module.cc | 66 +++++---------- DESERT_Addons/uwauv/uwauverror-b-module.cc | 69 ++++++++++++++-- DESERT_Addons/uwauv/uwauverror-b-module.h | 2 + DESERT_Addons/uwauv/uwauverror-module.cc | 82 ++++++++++++------- .../samples/desert_samples/AUV/asv_basic.tcl | 4 +- .../samples/desert_samples/AUV/auv_basic.tcl | 4 +- 7 files changed, 150 insertions(+), 91 deletions(-) diff --git a/DESERT_Addons/uwauv/uwauvctrer-b-module.cc b/DESERT_Addons/uwauv/uwauvctrer-b-module.cc index 12b4b77f..3e681efa 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-b-module.cc +++ b/DESERT_Addons/uwauv/uwauvctrer-b-module.cc @@ -261,9 +261,6 @@ void UwAUVCtrErBModule::initPkt(Packet* p) { << std::endl; } - /* TO DO */ - /* CHECK ALL THE STATE OF THE ERROR IN THE QUEUE, IF ONE OF THEM IS 2 THEN GO THERE*/ - if (!alarm_queue.empty()){ //take care of the next error x_err = alarm_queue[0][0]; @@ -286,7 +283,7 @@ void UwAUVCtrErBModule::initPkt(Packet* p) { }else{ uwAUVh->error() = 1; - uwAUVh->sn() = ++sn; + uwAUVh->sn() = sn; uwAUVh->x() = x_err; uwAUVh->y() = y_err; this->p = p; @@ -299,6 +296,15 @@ void UwAUVCtrErBModule::initPkt(Packet* p) { } } + + if (log_flag == 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_) { diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.cc b/DESERT_Addons/uwauv/uwauvctrer-module.cc index 84751903..9cb6a4da 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.cc +++ b/DESERT_Addons/uwauv/uwauvctrer-module.cc @@ -188,6 +188,13 @@ void UwAUVCtrErModule::setPosition(UWSMEPosition* p){ x_sorg = posit->getX(); y_sorg = posit->getY(); + if (log_flag == 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() { @@ -215,16 +222,12 @@ void UwAUVCtrErModule::initPkt(Packet* p) { hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); hdr_uwcbr *uwcbrh = HDR_UWCBR(p); - bool found = false; - uwAUVh->speed() = 0; + bool found = false; uwAUVh->ack() = ack; ack = 0; uwAUVh->error() = 0; - //if(this->p == NULL){ - //TO FIX - if (error_released){ uwAUVh->error() = -1; @@ -236,7 +239,7 @@ void UwAUVCtrErModule::initPkt(Packet* p) { if (log_flag == 1) { - err_log.open("log/error_log.csv",std::ios_base::app); + err_log.open("log/error_log_t.csv",std::ios_base::app); err_log << "G,"<< NOW << "," << x_s<<","<error() = 1; - uwAUVh->sn() = ++sn; + uwAUVh->sn() = sn; uwAUVh->x() = x_err; uwAUVh->y() = y_err; this->p = p; @@ -338,7 +338,6 @@ void UwAUVCtrErModule::initPkt(Packet* p) { } } - } @@ -346,21 +345,6 @@ void UwAUVCtrErModule::initPkt(Packet* p) { std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) ACK recv" << std::endl; } - - //Retransmission - /*}else{ - - uwAUVh->error() = -1; - uwAUVh->sn() = sn; - uwAUVh->x() = x_s; - uwAUVh->y() = y_s; - - - if (debug_) { - std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) Retransmission ERROR ("<< x_s << "," << y_s << ") solved" - << std::endl; - } - }*/ UwCbrModule::initPkt(p); @@ -391,7 +375,6 @@ void UwAUVCtrErModule::recv(Packet* p) { else if((uwAUVh->ack())<0 && debug_) std::cout << NOW << " UwAUVErrorModule::recv(Packet *p) error NACK " <<"received"<< std::endl; - if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { //obsolete packets @@ -445,19 +428,11 @@ void UwAUVCtrErModule::recv(Packet* p) { 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; } - //if (log_flag == 1) { - // err_log.open("log/error_log.csv",std::ios_base::app); - // err_log << "G,"<< NOW << "," << uwAUVh->x() <<","<y()<<", ON"<< std::endl; - // err_log.close(); - //} - - } @@ -493,7 +468,7 @@ void UwAUVCtrErModule::recv(Packet* p) { } if (log_flag == 1) { - err_log.open("log/error_log.csv",std::ios_base::app); + err_log.open("log/error_log_t.csv",std::ios_base::app); err_log << "R,"<< NOW << "," << x_err <<","<x(),uwAUVh->y()}); if (log_flag == 1) { - err_log.open("log/error_log.csv",std::ios_base::app); + 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(); } @@ -561,7 +536,7 @@ void UwAUVCtrErModule::recv(Packet* p) { if (!exists){ alarm_queue.push_back({uwAUVh->x(),uwAUVh->y()}); if (log_flag == 1) { - err_log.open("log/error_log.csv",std::ios_base::app); + err_log.open("log/error_log_t.csv",std::ios_base::app); err_log << "R,"<< NOW << "," << uwAUVh->x() <<","<y()<<", ON"<< std::endl; err_log.close(); } @@ -575,14 +550,13 @@ void UwAUVCtrErModule::recv(Packet* p) { }else{ - //delete point in gray_queue error_released = true; x_s = uwAUVh->x(); y_s = uwAUVh->y(); if (log_flag == 1) { - err_log.open("log/error_log.csv",std::ios_base::app); + 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(); } @@ -612,21 +586,21 @@ int UwAUVCtrErModule::checkError(double m, int n_pkt, float x, float y){ if (p_e <= accuracy){ //if p_e is small enough --> no error // NO ERROR - if (log_flag == 1) { + /*if (log_flag == 1) { t_err_log.open("log/true_error_log.csv",std::ios_base::app); t_err_log << NOW << "," << x <<","<< y <<","<< 0 << std::endl; t_err_log.close(); - } + }*/ status = 0; - }else if (p_e >= (1-accuracy)){ + }else if (p_e > (1-accuracy)){ // FOR SURE ERROR status = 2; - if (log_flag == 1) { + /*if (log_flag == 1) { t_err_log.open("log/true_error_log.csv",std::ios_base::app); t_err_log << NOW << "," << x <<","<< y <<","<< 1 << std::endl; t_err_log.close(); - } + }*/ }else{ //I NEED MORE DATA diff --git a/DESERT_Addons/uwauv/uwauverror-b-module.cc b/DESERT_Addons/uwauv/uwauverror-b-module.cc index 023c23d9..0d2973f1 100644 --- a/DESERT_Addons/uwauv/uwauverror-b-module.cc +++ b/DESERT_Addons/uwauv/uwauverror-b-module.cc @@ -88,6 +88,7 @@ UwAUVErrorBModule::UwAUVErrorBModule() , error_p(0.001) , alarm_mode(0) , speed(1) + , accuracy(0.01) { UWSMEPosition p = UWSMEPosition(); posit=&p; @@ -96,6 +97,8 @@ UwAUVErrorBModule::UwAUVErrorBModule() bind("log_flag_", (int*) &log_flag ); bind("period_", (int*) &period ); bind("error_p_", (int*) &error_p ); + bind("sigma_", (double*) &sigma); + bind("accuracy_",(double*) &accuracy); if (ackTimeout < 0) { cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" << std::endl; @@ -116,9 +119,10 @@ UwAUVErrorBModule::UwAUVErrorBModule(UWSMEPosition* p) , drop_old_waypoints(1) , log_flag(0) , period(60) - , error_p(0.001) + , error_p(0.01) , alarm_mode(0) , speed(1) + , accuracy(0.01) { posit = p; bind("ackTimeout_", (int*) &ackTimeout); @@ -126,6 +130,8 @@ UwAUVErrorBModule::UwAUVErrorBModule(UWSMEPosition* p) bind("log_flag_", (int*) &log_flag ); bind("period_", (int*) &period ); bind("error_p_", (int*) &error_p ); + bind("sigma_", (double*) &sigma); + bind("accuracy_",(double*) &accuracy); if (ackTimeout < 0) { cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" @@ -249,9 +255,26 @@ void UwAUVErrorBModule::initPkt(Packet* p) { std::mt19937 generator(rd()); std::uniform_real_distribution distrib(0.0, 1.0); - double randomValue = distrib(generator) ; + double t_e = distrib(generator) ; + + std::normal_distribution<> n_dis(0.0, sigma); // Adjust the standard deviation using the variance + + // Generate a random value from the Gaussian distribution + double noise = n_dis(generator); - if(randomValue < error_p){ + double m = t_e + noise; + + double p_e = std::erfc((((1 - error_p) - m) / std::sqrt(2.0)) / sigma); // prob of true error (t_e) greater than th_ne + + if (t_e > (1-error_p)){ + if (log_flag == 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 gray zone x_e = posit->getX(); y_e = posit->getY(); @@ -263,30 +286,58 @@ void UwAUVErrorBModule::initPkt(Packet* p) { uwAUVh->x() = x_e; uwAUVh->y() = y_e; uwAUVh->error() = 1; + uwAUVh->sn() = ++sn; + + if (log_flag == 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_flag == 1) { - err_log.open("log/error_log.csv",std::ios_base::app); - err_log << "E,"<< NOW << "," << x_e <<","<< y_e <<", ON"<< std::endl; - err_log.close(); + 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_flag == 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; } - uwAUVh->sn() = ++sn; + UwCbrModule::initPkt(p); if (log_flag == 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; + << "," << posit->getZ() << std::endl; out_file_stats.close(); } @@ -325,7 +376,7 @@ void UwAUVErrorBModule::recv(Packet* p) { if (log_flag == 1) { err_log.open("log/error_log.csv",std::ios_base::app); - err_log << "E,"<< NOW << "," << x_e <<","<< y_e <<", OFF"<< std::endl; + err_log << "OFF,"<< NOW << "," << x_e <<","<< y_e << std::endl; err_log.close(); } diff --git a/DESERT_Addons/uwauv/uwauverror-b-module.h b/DESERT_Addons/uwauv/uwauverror-b-module.h index 870d36ef..7d9410c1 100644 --- a/DESERT_Addons/uwauv/uwauverror-b-module.h +++ b/DESERT_Addons/uwauv/uwauverror-b-module.h @@ -215,6 +215,8 @@ class UwAUVErrorBModule : public UwCbrModule { double speed; double error_p; + double sigma; + double accuracy; }; diff --git a/DESERT_Addons/uwauv/uwauverror-module.cc b/DESERT_Addons/uwauv/uwauverror-module.cc index ef66383e..48636dc4 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.cc +++ b/DESERT_Addons/uwauv/uwauverror-module.cc @@ -264,26 +264,27 @@ void UwAUVErrorModule::initPkt(Packet* p) { }else{ - //if(posit->getX() != x_e or posit->getY() != y_e ){ - error_m = getErrorMeasure(); - if (debug_) { - std::cout << NOW << " UwAUVErroModule::initPkt(Packet *p) " - << "New error, measure: "<< error_m <<", true error: "<< t_e << std::endl; - } + 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){ if (log_flag == 1) { - err_log.open("log/error_log.csv",std::ios_base::app); + 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 @@ -296,8 +297,7 @@ void UwAUVErrorModule::initPkt(Packet* p) { uwAUVh->x() = x_e; uwAUVh->y() = y_e; uwAUVh->error() = error_m; - this->p = p; - + this->p = p; if (debug_) { std::cout << NOW << " UwAUVErroModule::initPkt(Packet *p) " @@ -312,24 +312,22 @@ void UwAUVErrorModule::initPkt(Packet* p) { } } + + uwAUVh->sn() = ++sn; }else{ + uwAUVh->x() = x_e; uwAUVh->y() = y_e; uwAUVh->error() = error_m; this->p = p; + uwAUVh->sn() = sn; } - uwAUVh->sn() = ++sn; + UwCbrModule::initPkt(p); - /*if (debug_){ - hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); - std::cout << NOW << " UwAUVErrorModule::initPkt(Packet *p) AUV current " - << "position: X = " << posit->getX() << ", Y = " << posit->getY() << std::endl; - }*/ - if (log_flag == 1) { out_file_stats.open("log/position_log_a.csv",std::ios_base::app); out_file_stats << NOW << "," << posit->getX() << ","<< posit->getY() @@ -377,12 +375,25 @@ void UwAUVErrorModule::recv(Packet* p) { sendTmr_.resched(period); if (log_flag == 1) { - err_log.open("log/error_log.csv",std::ios_base::app); + + 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(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(); + } + } if (debug_) { @@ -394,6 +405,23 @@ void UwAUVErrorModule::recv(Packet* p) { alarm_mode = 2; + if (log_flag == 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; @@ -460,24 +488,18 @@ double UwAUVErrorModule::getErrorMeasure(){ //double th_5sig = std::erfc((5*sigma) / std::sqrt(2)) / 2; - if (p_e >= accuracy){ //if p_e is small enough --> no error, otherwise gray zone + if (p_e > accuracy){ //if p_e is small enough --> no error, otherwise gray zone alarm_mode = 1; } if (t_e > th_ne){ + if (log_flag == 1) { t_err_log.open("log/true_error_log.csv",std::ios_base::app); - t_err_log << NOW << "," << x_e <<","<< y_e <<","<< 1 << std::endl; - t_err_log.close(); - } - }else{ - if (log_flag == 1) { - t_err_log.open("log/true_error_log.csv",std::ios_base::app); - t_err_log << NOW << "," << x_e <<","<< y_e <<","<< 0 << std::endl; + t_err_log << NOW << "," << x_e <<","<< y_e <<",e"<< std::endl; t_err_log.close(); } } - return m; diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv_basic.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv_basic.tcl index 53cbf7da..116fe6de 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv_basic.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv_basic.tcl @@ -27,7 +27,9 @@ proc createASV { id } { Module/UW/AUV/CEB set traffic_type_ 3 Module/UW/AUV/CEB set debug_ 0 Module/UW/AUV/CEB set log_flag_ 1 - Module/UW/AUV/CEB set errorp_ 0.01 + Module/UW/AUV/CEB set errrop_ $opt(e_prob) + Module/UW/AUV/CEB set sigma_ $opt(variance) + Module/UW/AUV/CEB set accuracy_ $opt(accuracy) for {set id1 0} {$id1 <= $opt(n_auv)} {incr id1} { diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv_basic.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv_basic.tcl index 50e67310..275c5fbd 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv_basic.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv_basic.tcl @@ -22,7 +22,9 @@ proc createAUV { id } { Module/UW/AUV/ERB set traffic_type_ 3 Module/UW/AUV/ERB set debug_ 0 Module/UW/AUV/ERB set log_flag_ 1 - Module/UW/AUV/ERB set errrop_ 0.01 + Module/UW/AUV/ERB set errrop_ $opt(e_prob) + Module/UW/AUV/ERB set sigma_ $opt(variance) + Module/UW/AUV/ERB set accuracy_ $opt(accuracy) set auv_err($id) [new Module/UW/AUV/ERB] From b7b1dc56ebb896c3689f2dcfb97a8f63593901d7 Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Fri, 7 Jul 2023 13:38:56 +0200 Subject: [PATCH 17/36] simulation analysis --- .../samples/desert_samples/AUV/metric_comp.py | 169 +++++++++ .../desert_samples/AUV/metric_comp_4.py | 165 +++++++++ .../desert_samples/AUV/plot_coordinates.py | 57 +-- .../AUV/plot_error_evolution.py | 170 +++++++++ .../desert_samples/AUV/result_compute.py | 341 ++++++++++++++++++ .../desert_samples/dbs/wp_path/rov_path.csv | 63 ++++ 6 files changed, 918 insertions(+), 47 deletions(-) create mode 100644 DESERT_Framework/DESERT/samples/desert_samples/AUV/metric_comp.py create mode 100644 DESERT_Framework/DESERT/samples/desert_samples/AUV/metric_comp_4.py create mode 100644 DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_error_evolution.py create mode 100644 DESERT_Framework/DESERT/samples/desert_samples/AUV/result_compute.py 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..ca16ab67 --- /dev/null +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/metric_comp.py @@ -0,0 +1,169 @@ +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 = [] + with open(file_path, 'r') as file: + reader = csv.reader(file) + for row in reader: + if (float(row[1]) < 0): + auv_1.append((float(row[1]),float(row[2]))) + else: + auv_2.append((float(row[1]),float(row[2]))) + + return auv_1,auv_2 + +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(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 = 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] + + # Calculate the total distance traveled + total_distance_1 = calculate_total_distance(auv_1) + total_distance_2 = calculate_total_distance(auv_2) + + +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,'\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..2abfe69b --- /dev/null +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/metric_comp_4.py @@ -0,0 +1,165 @@ +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_auv_coordinates_log(file_path): + pos = [] + auv_1 = [] + auv_2 = [] + with open(file_path, 'r') as file: + reader = csv.reader(file) + for row in reader: + if (float(row[1]) < 0): + auv_1.append((float(row[1]),float(row[2]))) + else: + auv_2.append((float(row[1]),float(row[2]))) + + return auv_1,auv_2 + +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(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 = 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] + + # Calculate the total distance traveled + total_distance_1 = calculate_total_distance(auv_1) + total_distance_2 = calculate_total_distance(auv_2) + + + +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,'\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 index 8c1a7091..402d6534 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_coordinates.py +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_coordinates.py @@ -41,7 +41,7 @@ def plot_movement_log(file_path,t,axis): X_1 = [] Y_1 = [] Z_1 = [] -file_path = 'postion_log_a.csv' # Replace with your file pathplot_coordinates(file_path) +file_path = 'log/position_log_a.csv' # Replace with your file pathplot_coordinates(file_path) plot_coordinates_log(file_path,X_1,Y_1) #file_path = 'test_uwauv1_results.csv' # Replace with your file pathplot_coordinates(file_path) #plot_coordinates(file_path,X_1,Y_1,Z_1) @@ -50,18 +50,18 @@ def plot_movement_log(file_path,t,axis): 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 = 'position_log.csv' # Replace with your file pathplot_coordinates(file_path) -plot_coordinates_log(file_path,X_s,Y_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) +#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) +#plot_coordinates_log(file_path,X_e_c,Y_e_c) X_0 = [] Y_0 = [] @@ -81,49 +81,12 @@ def plot_movement_log(file_path,t,axis): fig = plt.figure() ax = plt.subplot() -ax.plot(X_1, Y_1,'y.', label='auv_1') -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.plot(X_1, Y_1,'ko', label='auv_1') +#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() - -Axis = [] -t = [] -file_path = 'postion_log_a.csv' # Replace with your file pathplot_coordinates(file_path) -plot_movement_log(file_path,t,Axis) - -s_ax = [] -s_t = [] -file_path = 'position_log.csv' # Replace with your file pathplot_coordinates(file_path) -plot_movement_log(file_path,s_t,s_ax) - -X_e_c = [] -Y_e_c = [] -file_path = 'error_calling_log.csv' # Replace with your file pathplot_coordinates(file_path) -plot_movement_log(file_path,X_e_c,Y_e_c) - -X_e_s = [] -Y_e_s = [] -file_path = 'error_log_a.csv' # Replace with your file pathplot_coordinates(file_path) -plot_movement_log(file_path,X_e_s,Y_e_s) - -X_e = [] -Y_e = [] -file_path = 'error_log.csv' # Replace with your file pathplot_coordinates(file_path) -plot_movement_log(file_path,X_e,Y_e) - -fig = plt.figure() -ax = plt.subplot() -ax.plot(Z_1a, X_1a,'y--', label='auv_1') -ax.plot(Z_0, X_0,'m--', label='auv_1') -ax.plot(t, Axis,'k.', label='auv_1') -ax.plot(s_t, s_ax,'g--', label='asv') -ax.plot(X_e_c, Y_e_c, 'b^',label='error_called') -ax.plot(X_e_s, Y_e_s, 'bx',label='error_solved') -ax.plot(X_e, Y_e, 'rx',label='error_Solved') -ax.legend() -plt.show() +plt.show() \ 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..7c335620 --- /dev/null +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_error_evolution.py @@ -0,0 +1,170 @@ +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] + +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 = 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,'g--', label='sv') +ax.plot(x_a, y_a,'m.', label='sv') +ax.plot(g_on_x, g_on_y,'ko', label='g_error_on') +ax.plot(g_off_x, g_off_y,'kx', label='g_error_off') +ax.plot(r_on_x, r_on_y,'ro', label='r_error_on') +ax.plot(r_off_x,r_off_y,'rx', 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..003d14d2 --- /dev/null +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/result_compute.py @@ -0,0 +1,341 @@ +import matplotlib.pyplot as plt +import numpy as np +from scipy import stats +import seaborn as sns +import pandas as pd + +def compute_error(file_path): + d_1 = {} + d_2 = {} + m_t = {} + m_d ={} + m_tp={} + m_fp={} + m_tn={} + m_fn={} + acc=[] + pr = {} + rc = {} + e = {} + with open(file_path, 'r') as file: + 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])] + m_d[float(row[0])]=[float(row[5])/float(row[10])] + else: + m_t[float(row[0])]=[float(row[4])] + m_d[float(row[0])]=[float(row[5])] + + d_1[float(row[0])]=[float(row[11])] + d_2[float(row[0])]=[float(row[12])] + + m_fn[float(row[0])]=[float(row[7])] + m_tn[float(row[0])]=[float(row[8])] + m_fp[float(row[0])]=[float(row[9])] + + e[float(row[0])]=[float(row[10])] + + + if float(row[10]): + 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]): + rc[float(row[0])]=[float(row[6])/(float(row[6])+float(row[7]))] + + 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])) + + if float(row[10]): + m_t[float(row[0])].append(float(row[4])/float(row[10])) + m_d[float(row[0])].append(float(row[5])/float(row[10])) + else: + m_t[float(row[0])].append(float(row[4])) + m_d[float(row[0])].append(float(row[5])) + + 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])) + + if float(row[10]): + if float(row[0]) in m_tp: + m_tp[float(row[0])].append(float(row[6])) + if float(row[6])+float(row[9]): + pr[float(row[0])].append(float(row[6])/(float(row[6])+float(row[9]))) + if float(row[6])+float(row[7]): + rc[float(row[0])].append(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]): + 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 + + +file_path = "result.csv" + +m1_t,m1_d,m1_tp,m1_fp,m1_tn,m1_fn,acc1,pr1,rc1, d11,d12 = compute_error(file_path) + +file_path = "result_2.csv" + +m2_t,m2_d,m2_tp,m2_fp,m2_tn,m2_fn,acc2,pr2,rc2,d21,d22 = compute_error(file_path) + + + +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',markers=True,label='smart') + +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'] +print(pr2['Key']) +sns.lineplot(data=pr2,x='Key',y='Values',markers=True,label='basic') + +plt.title('Precision') +plt.xscale('log') +plt.grid() +plt.xlabel('Accuracy') +ax.legend() +plt.show() + + +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',markers='o',label='smart') + +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',markers='o',label='basic') + +plt.title('Recall') +plt.xscale('log') +plt.grid() +plt.xlabel('Accuracy') +ax.legend() +plt.show() + + +# m1_tp = {'Key':m1_t.keys(), +# 'Values':m1_tp.values()} +# m1_tp = pd.DataFrame(m1_tp) + +# ax = plt.figure() +# m1_tp = m1_tp.explode('Values') +# m1_tp = m1_tp.reset_index(drop=True) +# m1_tp.columns= ['Key','Values'] +# sns.lineplot(data=m1_tp,x='Key',y='Values',label='smart') + +# m2_tp = {'Key':m2_t.keys(), +# 'Values':m2_tp.values()} +# tp_df = pd.DataFrame(m2_tp) +# 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',label='basic') + +# plt.title('True positive') +# plt.xscale('log') +# plt.grid() +# plt.xlabel('Accuracy') +# ax.legend() +# plt.show() + +# plt.figure() +# #plt.errorbar(m_fp.keys(),mean_fp,yerr=ci_fp,label='fp',fmt='o',color='#1f77b4') +# #plt.plot(m_fp.keys(),mean_fp,'o--',color='#1f77b4') +# data = {'Key':m1_t.keys(), +# 'Values':m1_fp.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',label='smart') + +# data = {'Key':m2_t.keys(), +# 'Values':m2_fp.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',label='basic') +# plt.xscale('log') +# plt.grid() +# plt.title('False positive') +# plt.xlabel('Accuracy') +# plt.show() + +# plt.figure() +# #plt.errorbar(m_fn.keys(),mean_fn,yerr=ci_fn,label='fn',fmt='o',color='#1f77b4') +# #plt.plot(m_fn.keys(),mean_fn,'^--',color='#1f77b4') +# data = {'Key':m1_t.keys(), +# 'Values':m1_fn.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',label='smart') +# data = {'Key':m2_t.keys(), +# 'Values':m2_fn.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',label='basic') +# plt.grid() +# plt.xscale('log') +# plt.title('False negative') +# plt.xlabel('Accuracy') +# plt.show() + +# plt.figure() +# #plt.errorbar(m_tn.keys(),mean_tn,yerr=ci_tn,label='tn',fmt='o',color='#1f77b4') +# #plt.plot(m_tn.keys(),mean_tn,'^--',color='#1f77b4') +# data = {'Key':m1_t.keys(), +# 'Values':m1_tn.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',label='smart') + +# data = {'Key':m2_t.keys(), +# 'Values':m2_tn.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',label='basic') + +# plt.xscale('log') +# plt.title('True negative') +# plt.xlabel('Accuracy') +# plt.grid() +# plt.show() + +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',label='smart') + +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',label='basic') + +ax.legend() +plt.xscale('log') +plt.yscale('log') +plt.xlabel('Accuracy') +plt.ylabel('Distance') +plt.grid() +plt.show() + +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',label='smart') + +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',label='basic') +ax.legend() +plt.xscale('log') +plt.yscale('log') +plt.xlabel('Accuracy') +plt.ylabel('Time') +plt.show() + +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',label='smart_1') + +data = {'Key':d12.keys(), + 'Values':d12.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',label='smart_2') + +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',label='basic_1') + +data = {'Key':d22.keys(), + 'Values':d22.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',label='basic_2') + +ax.legend() +plt.xscale('log') +plt.yscale('log') +plt.xlabel('Accuracy') +plt.ylabel('Distance covered') +plt.show() + + 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 From c50cc9641ef7279970ad7f17ecfa931abffe0967 Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Fri, 7 Jul 2023 13:39:25 +0200 Subject: [PATCH 18/36] sim fixed --- .../desert_samples/AUV/test_uwauv_error.tcl | 11 ++++++++--- .../desert_samples/AUV/test_uwauv_error_basic.tcl | 15 ++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) 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 index ff245189..c080b29c 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwauv_error.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwauv_error.tcl @@ -127,7 +127,7 @@ $ns use-Miracle ################## set opt(n_auv) 2 ;# Number of Nodes set opt(starttime) 1 -set opt(stoptime) 15000 +set opt(stoptime) 150000 set opt(txduration) [expr $opt(stoptime) - $opt(starttime)] set opt(rngstream) 1 @@ -362,8 +362,8 @@ for {set id 0} {$id < $opt(n_auv)} {incr id} { Position/UWSME debug_ 1 set position_auv($id) [new "Position/UWSME"] - $position_auv($id) setX_ 0 - $position_auv($id) setY_ 0 + $position_auv($id) setX_ 1*($id*(2))-1 + $position_auv($id) setY_ 1*($id*(-2))-1 $position_auv($id) setZ_ -1000 $auv_app($id) setPosition $position_auv($id) @@ -441,6 +441,11 @@ proc update_and_check {t} { close $outfile_auv close $outfile_asv + if {[$auv_app(0) getX] == -510.0 && [$auv_app(0) getY] == 510.0 && [$auv_app(1) getX] == 510.0 && [$auv_app(1) getY] == -510.0} { + puts "STOP" + ns "finish; $ns halt" + } + } ### 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 index 32f1311c..b1207dbd 100644 --- 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 @@ -74,7 +74,7 @@ # Flags to enable or disable options # ###################################### set opt(trace_files) 0 -set opt(bash_parameters) 0 +set opt(bash_parameters) 1 ##################### # Library Loading # @@ -127,7 +127,7 @@ $ns use-Miracle ################## set opt(n_auv) 2 ;# Number of Nodes set opt(starttime) 1 -set opt(stoptime) 15000 +set opt(stoptime) 150000 set opt(txduration) [expr $opt(stoptime) - $opt(starttime)] set opt(rngstream) 3 @@ -186,7 +186,7 @@ if {$opt(bash_parameters)} { puts "The script requires two inputs:" puts "- the first for accuracy" puts "- the second for variance" - puts "- the third error probability" + 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" @@ -362,8 +362,8 @@ for {set id 0} {$id < $opt(n_auv)} {incr id} { Position/UWSME debug_ 1 set position_auv($id) [new "Position/UWSME"] - $position_auv($id) setX_ 0 - $position_auv($id) setY_ 0 + $position_auv($id) setX_ 1*($id*(2))-1 + $position_auv($id) setY_ 1*($id*(-2))-1 $position_auv($id) setZ_ -1000 $auv_app($id) setPosition $position_auv($id) @@ -424,6 +424,8 @@ for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { } 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"] @@ -433,6 +435,7 @@ proc update_and_check {t} { 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]" @@ -440,8 +443,6 @@ proc update_and_check {t} { close $outfile_auv close $outfile_asv - - } ### From da3bed683ec6ba80f08ad7acea0c0af0a8645d9b Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Sun, 23 Jul 2023 00:09:17 +0200 Subject: [PATCH 19/36] double tx correction --- DESERT_Addons/uwauv/uwauv-module.cc | 17 ++- DESERT_Addons/uwauv/uwauv-module.h | 1 - DESERT_Addons/uwauv/uwauvctr-module.cc | 11 +- DESERT_Addons/uwauv/uwauvctrer-b-module.cc | 64 +--------- DESERT_Addons/uwauv/uwauvctrer-b-module.h | 9 +- DESERT_Addons/uwauv/uwauvctrer-module.cc | 44 +------ DESERT_Addons/uwauv/uwauvctrer-module.h | 15 +-- DESERT_Addons/uwauv/uwauverror-b-module.cc | 83 +++---------- DESERT_Addons/uwauv/uwauverror-b-module.h | 11 -- DESERT_Addons/uwauv/uwauverror-module.cc | 130 +++------------------ DESERT_Addons/uwauv/uwauverror-module.h | 13 --- 11 files changed, 56 insertions(+), 342 deletions(-) diff --git a/DESERT_Addons/uwauv/uwauv-module.cc b/DESERT_Addons/uwauv/uwauv-module.cc index 5b5a6cf7..256623c3 100644 --- a/DESERT_Addons/uwauv/uwauv-module.cc +++ b/DESERT_Addons/uwauv/uwauv-module.cc @@ -219,15 +219,13 @@ int UwAUVModule::command(int argc, const char*const* argv) { } void UwAUVModule::initPkt(Packet* p) { + hdr_uwAUV_monitoring* uwAUVh = HDR_UWAUV_MONITORING(p); - //hdr_uwAUV_ctr* uwAUVh = HDR_UWAUV_CTR(p); + hdr_uwcbr *uwcbrh = HDR_UWCBR(p); uwAUVh->x() = posit->getX(); uwAUVh->y() = posit->getY(); uwAUVh->z() = posit->getZ(); - //uwAUVh->speed() = 200; - - //uwAUVh->ack() = ack; ack=0; @@ -243,6 +241,7 @@ void UwAUVModule::initPkt(Packet* p) { std::cout << NOW << " UwAUVModule::sending packet with priority " << (int)uwcbrh->priority() << std::endl; } + priority_ = 0; } @@ -255,14 +254,17 @@ void UwAUVModule::recv(Packet* p) { hdr_uwAUV_ctr* uwAUVh = HDR_UWAUV_CTR(p); if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { //obsolete packets + 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; @@ -277,12 +279,13 @@ void UwAUVModule::recv(Packet* p) { } - if (debug_) { + 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) { if (ackPriority == 0) { @@ -304,6 +307,7 @@ void UwAUVModule::recv(Packet* p) { } void UwAUVModule::sendAck() { + ackNotPgbk++; if (ackPriority == 0) { UwCbrModule::sendPkt(); @@ -316,4 +320,5 @@ void UwAUVModule::sendAck() { 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 index 3e0b35da..5f36457d 100644 --- a/DESERT_Addons/uwauv/uwauv-module.h +++ b/DESERT_Addons/uwauv/uwauv-module.h @@ -169,7 +169,6 @@ class UwAUVModule : public UwCbrModule { UWSMEPosition* 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.*/ - //int send_ack_immediately; /**< Flag either to send acks immediately or not.*/ 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, diff --git a/DESERT_Addons/uwauv/uwauvctr-module.cc b/DESERT_Addons/uwauv/uwauvctr-module.cc index 7fbb7b9d..6699aa1c 100644 --- a/DESERT_Addons/uwauv/uwauvctr-module.cc +++ b/DESERT_Addons/uwauv/uwauvctr-module.cc @@ -28,7 +28,7 @@ /** * @file uwauvctr-module.cc -* @author Filippo Campagnaro +* @author Filippo Campagnaro, Alessia Ortile * @version 1.0.0 * * \brief Provides the UWAUVCtr class implementation. @@ -74,11 +74,9 @@ UwAUVCtrModule::UwAUVCtrModule(UWSMEPosition* p) , sn(0) , adaptiveRTO(0) , adaptiveRTO_parameter(0.5) - //, sumrttAck(0) - //, rttAcksamples(0) { posit=p; - speed=1; + speed=0.5; bind("adaptiveRTO_", (int *) &adaptiveRTO); if (adaptiveRTO == 1) { bind("adaptiveRTO_parameter_", (double *) &adaptiveRTO_parameter); @@ -95,14 +93,12 @@ UwAUVCtrModule::UwAUVCtrModule() , sn(0) , adaptiveRTO(0) , adaptiveRTO_parameter(0.5) - //, sumrttAck(0) - //, rttAcksamples(0) { p = NULL; UWSMEPosition p = UWSMEPosition(); posit=&p; //posit = Position(); - speed = 1; + speed = 0.5; bind("adaptiveRTO_", (int *) &adaptiveRTO); if (adaptiveRTO == 1) { bind("adaptiveRTO_parameter_", (double *) &adaptiveRTO_parameter); @@ -253,6 +249,7 @@ void UwAUVCtrModule::recv(Packet* p) { hdr_uwcbr *uwcbrh = HDR_UWCBR(p); hdr_cmn *ch = hdr_cmn::access(p); + if(monitoring->ack() == sn + 1) { sendTmr_.force_cancel(); this->p = NULL; diff --git a/DESERT_Addons/uwauv/uwauvctrer-b-module.cc b/DESERT_Addons/uwauv/uwauvctrer-b-module.cc index 3e681efa..1535c294 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-b-module.cc +++ b/DESERT_Addons/uwauv/uwauvctrer-b-module.cc @@ -72,41 +72,30 @@ static class UwAUVCtrErBModuleClass : public TclClass { UwAUVCtrErBModule::UwAUVCtrErBModule(UWSMEPosition* p) : UwCbrModule() - , ack(0) , last_sn_confirmed(0) , sn(0) - , ackTimeout(10) , drop_old_waypoints(1) , log_flag(0) , period(60) - , speed(4) + , speed(1.5) { posit=p; x_sorg = posit->getX(); y_sorg = posit->getY(); - bind("ackTimeout_", (int*) &ackTimeout); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); bind("log_flag_", (int*) &log_flag ); bind("period_", (int*) &period ); - - if (ackTimeout < 0) { - cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" - << std::endl; - ackTimeout = 10; - } } UwAUVCtrErBModule::UwAUVCtrErBModule() : UwCbrModule() - , ack(0) , last_sn_confirmed(0) , sn(0) - , ackTimeout(10) , drop_old_waypoints(1) , log_flag(0) , period(60) - , speed(4) + , speed(1.5) { p = NULL; @@ -115,17 +104,10 @@ UwAUVCtrErBModule::UwAUVCtrErBModule() x_sorg = posit->getX(); y_sorg = posit->getY(); - bind("ackTimeout_", (int*) &ackTimeout); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); bind("log_flag_", (int*) &log_flag ); bind("period_", (int*) &period ); - if (ackTimeout < 0) { - cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" - << std::endl; - ackTimeout = 10; - } - } UwAUVCtrErBModule::~UwAUVCtrErBModule() {} @@ -172,8 +154,6 @@ int UwAUVCtrErBModule::command(int argc, const char*const* argv) { return UwCbrModule::command(argc,argv); } -void UwAUVCtrErBModule::start() {} - void UwAUVCtrErBModule::setPosition(UWSMEPosition* p){ posit = p; @@ -208,12 +188,8 @@ void UwAUVCtrErBModule::initPkt(Packet* p) { hdr_uwcbr *uwcbrh = HDR_UWCBR(p); bool found = false; - uwAUVh->ack() = ack; - ack = 0; uwAUVh->error() = 0; - - if (alarm_mode){ if ((getDistance(posit->getX(),posit->getY(),x_err,y_err) == 0.0)){ //If in the right position @@ -275,7 +251,7 @@ void UwAUVCtrErBModule::initPkt(Packet* p) { y_sorg = posit->getY(); if (debug_) { - std::cout << NOW << " UwAUVCtrErrModule::initPkt(Packet *p) SV picked a new " + std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) SV picked a new " "error from the queue: X = " << x_err << ", Y = " << y_err<< std::endl; } } @@ -307,18 +283,7 @@ void UwAUVCtrErBModule::initPkt(Packet* p) { } - if (debug_) { - std::cout << NOW << " UwAUVCtrErBModule::initPkt(Packet *p) ACK recv" - << std::endl; - } - UwCbrModule::initPkt(p); - - if (debug_) { - std::cout << NOW << " UwAUVCtrErBModule::initPkt(Packet *p) setting last ack" - << std::endl; - } - } void UwAUVCtrErBModule::recv(Packet* p, Handler* h) { @@ -331,23 +296,9 @@ void UwAUVCtrErBModule::recv(Packet* p) { bool exist = false; - if(uwAUVh->ack() == sn + 1) { //ack received - this->p = NULL; - } - - - if(uwAUVh->ack() > 0 && debug_) - std::cout << NOW << " UwAUVErrorModule::recv(Packet *p) error ACK " - << "received " << uwAUVh->ack()<< std::endl; - else if((uwAUVh->ack())<0 && debug_) - std::cout << NOW << " UwAUVErrorModule::recv(Packet *p) error NACK " - <<"received"<< std::endl; - - - if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { //obsolete packets if (debug_) { - std::cout << NOW << " UwAUVCtrErrModule::old error with sn " + std::cout << NOW << " UwAUVCtrErBModule::old error with sn " << uwAUVh->sn() << " dropped " << std::endl; } @@ -356,7 +307,7 @@ void UwAUVCtrErBModule::recv(Packet* p) { if (uwAUVh->error() == 0){// AUV MARKED IT AS NO ERROR if (debug_) - std::cout << NOW << " UwAUVCtrErrModule:: no error" << std::endl; + std::cout << NOW << " UwAUVCtrErBModule:: no error" << std::endl; }else{ // error @@ -401,7 +352,6 @@ void UwAUVCtrErBModule::recv(Packet* p) { exist = false; for (const auto& vec : alarm_queue) { - // Controlla se le coordinate corrispondono if (vec[0] == uwAUVh->x() && vec[1] == uwAUVh->y()) { exist = true; break; @@ -457,10 +407,8 @@ void UwAUVCtrErBModule::recv(Packet* p) { last_sn_confirmed = uwAUVh->sn(); } - ack = last_sn_confirmed+1; - UwCbrModule::recv(p); - UwCbrModule::sendPkt(); + //transmit(); } diff --git a/DESERT_Addons/uwauv/uwauvctrer-b-module.h b/DESERT_Addons/uwauv/uwauvctrer-b-module.h index 605675f4..d21db0cd 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-b-module.h +++ b/DESERT_Addons/uwauv/uwauvctrer-b-module.h @@ -113,11 +113,6 @@ class UwAUVCtrErBModule : public UwCbrModule { */ virtual void initPkt(Packet* p) ; - /** - * Reset retransmissions - */ - //inline void reset_retx() {p=NULL; sendTmr_.force_cancel();} - /** * Set the position of the AUVCtr * @@ -164,7 +159,7 @@ class UwAUVCtrErBModule : public UwCbrModule { /** * Start the controller. */ - virtual void start(); + //virtual void start(); /** * Returns the size in byte of a hdr_uwAUV_monitoring packet header. @@ -196,7 +191,6 @@ class UwAUVCtrErBModule : public UwCbrModule { UWSMEPosition* 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 ack; int drop_old_waypoints; int period; @@ -208,7 +202,6 @@ class UwAUVCtrErBModule : public UwCbrModule { Packet* p; int log_flag; - int ackTimeout; float x_sorg; float y_sorg; double speed; diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.cc b/DESERT_Addons/uwauv/uwauvctrer-module.cc index 9cb6a4da..bb8bbb9e 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.cc +++ b/DESERT_Addons/uwauv/uwauvctrer-module.cc @@ -72,21 +72,18 @@ static class UwAUVCtrErModuleClass : public TclClass { UwAUVCtrErModule::UwAUVCtrErModule(UWSMEPosition* p) : UwCbrModule() - , ack(0) , last_sn_confirmed(0) , sn(0) - , ackTimeout(10) , drop_old_waypoints(1) , log_flag(0) , period(60) - , speed(4) + , speed(1.5) , accuracy(0.001) { posit=p; x_sorg = posit->getX(); y_sorg = posit->getY(); - bind("ackTimeout_", (int*) &ackTimeout); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); bind("log_flag_", (int*) &log_flag ); bind("period_", (int*) &period ); @@ -94,23 +91,16 @@ UwAUVCtrErModule::UwAUVCtrErModule(UWSMEPosition* p) bind("th_ne_", (double*) &th_ne ); bind("accuracy_ne_", (double*) &accuracy ); - if (ackTimeout < 0) { - cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" - << std::endl; - ackTimeout = 10; - } } UwAUVCtrErModule::UwAUVCtrErModule() : UwCbrModule() - , ack(0) , last_sn_confirmed(0) , sn(0) - , ackTimeout(10) , drop_old_waypoints(1) , log_flag(0) , period(60) - , speed(4) + , speed(1.5) , accuracy(0.001) { @@ -120,7 +110,6 @@ UwAUVCtrErModule::UwAUVCtrErModule() x_sorg = posit->getX(); y_sorg = posit->getY(); - bind("ackTimeout_", (int*) &ackTimeout); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); bind("log_flag_", (int*) &log_flag ); bind("period_", (int*) &period ); @@ -128,12 +117,6 @@ UwAUVCtrErModule::UwAUVCtrErModule() bind("th_ne_", (double*) &th_ne ); bind("accuracy_ne_", (double*) &accuracy ); - if (ackTimeout < 0) { - cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" - << std::endl; - ackTimeout = 10; - } - } UwAUVCtrErModule::~UwAUVCtrErModule() {} @@ -180,7 +163,6 @@ int UwAUVCtrErModule::command(int argc, const char*const* argv) { return UwCbrModule::command(argc,argv); } -void UwAUVCtrErModule::start() {} void UwAUVCtrErModule::setPosition(UWSMEPosition* p){ @@ -205,7 +187,6 @@ void UwAUVCtrErModule::transmit() { std::cout << NOW << " UwAUVCtrErModule::Sending pkt with period: " << period << std::endl; } - sendTmr_.resched(period); } @@ -224,8 +205,6 @@ void UwAUVCtrErModule::initPkt(Packet* p) { hdr_uwcbr *uwcbrh = HDR_UWCBR(p); bool found = false; - uwAUVh->ack() = ack; - ack = 0; uwAUVh->error() = 0; if (error_released){ @@ -362,20 +341,7 @@ void UwAUVCtrErModule::recv(Packet* p, Handler* h) { void UwAUVCtrErModule::recv(Packet* p) { hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); - - - if(uwAUVh->ack() == sn + 1) { //ack received - this->p = NULL; - } - - - if(uwAUVh->ack() > 0 && debug_) - std::cout << NOW << " UwAUVErrorModule::recv(Packet *p) error ACK " - << "received " << uwAUVh->ack()<< std::endl; - else if((uwAUVh->ack())<0 && debug_) - std::cout << NOW << " UwAUVErrorModule::recv(Packet *p) error NACK " - <<"received"<< std::endl; - + if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { //obsolete packets if (debug_) { @@ -570,10 +536,8 @@ void UwAUVCtrErModule::recv(Packet* p) { last_sn_confirmed = uwAUVh->sn(); } - ack = last_sn_confirmed+1; - UwCbrModule::recv(p); - UwCbrModule::sendPkt(); + //transmit(); } int UwAUVCtrErModule::checkError(double m, int n_pkt, float x, float y){ diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.h b/DESERT_Addons/uwauv/uwauvctrer-module.h index 7cd9f6ec..04c81ad6 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.h +++ b/DESERT_Addons/uwauv/uwauvctrer-module.h @@ -116,7 +116,7 @@ class UwAUVCtrErModule : public UwCbrModule { /** * Reset retransmissions */ - //inline void reset_retx() {p=NULL; sendTmr_.force_cancel();} + inline void reset_retx() {p=NULL; sendTmr_.force_cancel();} /** * Set the position of the AUVCtr @@ -132,12 +132,6 @@ class UwAUVCtrErModule : public UwCbrModule { */ inline UWSMEPosition* getPosition() { return posit;} - /** - * Reset retransmissions - */ - inline void reset_retx() {p=NULL; sendTmr_.force_cancel();} - - /** * Creates and transmits a packet. * @@ -161,11 +155,6 @@ class UwAUVCtrErModule : public UwCbrModule { */ virtual void recv(Packet* p, Handler* h); - /** - * Start the controller. - */ - virtual void start(); - /** * Returns the size in byte of a hdr_uwAUV_monitoring packet header. * @@ -196,7 +185,6 @@ class UwAUVCtrErModule : public UwCbrModule { UWSMEPosition* 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 ack; int drop_old_waypoints; int period; @@ -208,7 +196,6 @@ class UwAUVCtrErModule : public UwCbrModule { Packet* p; int log_flag; - int ackTimeout; float x_sorg; float y_sorg; double speed; diff --git a/DESERT_Addons/uwauv/uwauverror-b-module.cc b/DESERT_Addons/uwauv/uwauverror-b-module.cc index 0d2973f1..0e5ed12a 100644 --- a/DESERT_Addons/uwauv/uwauverror-b-module.cc +++ b/DESERT_Addons/uwauv/uwauverror-b-module.cc @@ -44,12 +44,7 @@ extern packet_t PT_UWCBR; extern packet_t PT_UWAUV; extern packet_t PT_UWAUV_CTR; extern packet_t PT_UWAUV_ERROR; -/** -* Adds the header for hdr_uwAUVError packets in ns2. -*/ -/** -* Adds the module for UwAUVModuleClass in ns2. -*/ + /** * Class that represents the binding with the tcl configuration script @@ -78,33 +73,22 @@ UwAUVErrorBModule::UwAUVErrorBModule() : UwCbrModule() , last_sn_confirmed(0) , sn(0) - , ack(0) - , ackPolicy(ACK_PIGGYBACK) - , ackTimeout(10) - , ackNotPgbk(0) , drop_old_waypoints(1) , log_flag(0) , period(60) , error_p(0.001) , alarm_mode(0) - , speed(1) + , speed(0.5) , accuracy(0.01) { UWSMEPosition p = UWSMEPosition(); posit=&p; - bind("ackTimeout_", (int*) &ackTimeout); - bind("drop_old_waypoints_", (int*) &drop_old_waypoints); + bind("drop_old_waypoints_", (int*) &drop_old_waypoints); bind("log_flag_", (int*) &log_flag ); bind("period_", (int*) &period ); bind("error_p_", (int*) &error_p ); bind("sigma_", (double*) &sigma); bind("accuracy_",(double*) &accuracy); - if (ackTimeout < 0) { - cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" - << std::endl; - ackTimeout = 10; - } - } @@ -112,20 +96,15 @@ UwAUVErrorBModule::UwAUVErrorBModule(UWSMEPosition* p) : UwCbrModule() , last_sn_confirmed(0) , sn(0) - , ack(0) - , ackPolicy(ACK_PIGGYBACK) - , ackTimeout(10) - , ackNotPgbk(0) , drop_old_waypoints(1) , log_flag(0) , period(60) , error_p(0.01) , alarm_mode(0) - , speed(1) + , speed(0.5) , accuracy(0.01) { posit = p; - bind("ackTimeout_", (int*) &ackTimeout); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); bind("log_flag_", (int*) &log_flag ); bind("period_", (int*) &period ); @@ -133,14 +112,6 @@ UwAUVErrorBModule::UwAUVErrorBModule(UWSMEPosition* p) bind("sigma_", (double*) &sigma); bind("accuracy_",(double*) &accuracy); - if (ackTimeout < 0) { - cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" - << std::endl; - ackTimeout = 10; - } - - - } UwAUVErrorBModule::~UwAUVErrorBModule() {} @@ -175,10 +146,6 @@ int UwAUVErrorBModule::command(int argc, const char*const* argv) { 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) { @@ -187,24 +154,6 @@ int UwAUVErrorBModule::command(int argc, const char*const* argv) { tcl.resultf("%s", "position Setted\n"); return TCL_OK; } - 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; - } - } - if (strcasecmp(argv[1], "setAckTimeout") == 0) { - ackTimeout = atof(argv[2]); - return TCL_OK; - } } else if(argc == 5){ if (strcasecmp(argv[1], "setdest") == 0) { @@ -245,8 +194,6 @@ void UwAUVErrorBModule::initPkt(Packet* p) { hdr_uwcbr *uwcbrh = HDR_UWCBR(p); hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); - uwAUVh->ack() = ack; - ack = 0; uwAUVh->error() = 0; if (!alarm_mode){ @@ -257,9 +204,9 @@ void UwAUVErrorBModule::initPkt(Packet* p) { double t_e = distrib(generator) ; - std::normal_distribution<> n_dis(0.0, sigma); // Adjust the standard deviation using the variance + std::normal_distribution<> n_dis(0.0, sigma); + - // Generate a random value from the Gaussian distribution double noise = n_dis(generator); double m = t_e + noise; @@ -337,7 +284,7 @@ void UwAUVErrorBModule::initPkt(Packet* p) { if (log_flag == 1) { out_file_stats.open("log/position_log_a.csv",std::ios_base::app); out_file_stats << NOW << "," << posit->getX() << ","<< posit->getY() - << "," << posit->getZ() << std::endl; + << "," << posit->getZ() << ',' << posit->getSpeed() << std::endl; out_file_stats.close(); } @@ -350,15 +297,11 @@ void UwAUVErrorBModule::recv(Packet* p, Handler* h) { void UwAUVErrorBModule::recv(Packet* p) { hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); - - if(uwAUVh->ack() == sn + 1) { - this->p = NULL; - } if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { //obsolete packets if (debug_) { - std::cout << NOW << " UwAUVErrModule::old error with sn " + std::cout << NOW << " UwAUVErrBModule::old error with sn " << uwAUVh->sn() << " dropped " << std::endl; } @@ -371,6 +314,8 @@ void UwAUVErrorBModule::recv(Packet* p) { 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); @@ -381,7 +326,7 @@ void UwAUVErrorBModule::recv(Packet* p) { } if (debug_) { - std::cout << NOW << " UwAUVErrModule::recv(Packet *p) error ("<< x_e <<","<< y_e <<") solved " + std::cout << NOW << " UwAUVErrBModule::recv(Packet *p) error ("<< x_e <<","<< y_e <<") solved " "AUV can move again with speed=" << posit->getSpeed()<< std::endl; } @@ -390,7 +335,7 @@ void UwAUVErrorBModule::recv(Packet* p) { alarm_mode = true; if (debug_) - std::cout << NOW << " UwAUVErrModule::recv(Packet *p) for SURE there is an error ("<< x_e <<","<< y_e <<")" + std::cout << NOW << " UwAUVErrBModule::recv(Packet *p) for SURE there is an error ("<< x_e <<","<< y_e <<")" "STOP until ctr arrival"<< std::endl; } @@ -399,10 +344,8 @@ void UwAUVErrorBModule::recv(Packet* p) { last_sn_confirmed = uwAUVh->sn(); } - ack = last_sn_confirmed+1; UwCbrModule::recv(p); - UwCbrModule::sendPkt(); if(uwAUVh->ack() > 0 && debug_) std::cout << NOW << " UwAUVErrorBModule::recv(Packet *p) error ACK " @@ -414,7 +357,7 @@ void UwAUVErrorBModule::recv(Packet* p) { if (log_flag == 1) { out_file_stats.open("log/position_log_a.csv",std::ios_base::app); out_file_stats << NOW << "," << posit->getX() << ","<< posit->getY() - << "," << posit->getZ() << std::endl; + << "," << posit->getZ() << ',' << posit->getSpeed() << std::endl; out_file_stats.close(); } diff --git a/DESERT_Addons/uwauv/uwauverror-b-module.h b/DESERT_Addons/uwauv/uwauverror-b-module.h index 7d9410c1..73d2955b 100644 --- a/DESERT_Addons/uwauv/uwauverror-b-module.h +++ b/DESERT_Addons/uwauv/uwauverror-b-module.h @@ -185,18 +185,7 @@ class UwAUVErrorBModule : public UwCbrModule { UWSMEPosition* posit; /**< AUV position.*/ int last_sn_confirmed;/**< Sequence number of the last command Packete received.*/ int sn; - int ack; - //int send_ack_immediately; /**< Flag either to send acks immediately or not.*/ 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.*/ - int ackTimeout; /**< Timeout after which ACK is sent if ackPolicy = ACK_PGBK_OR_TO. */ - 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.*/ diff --git a/DESERT_Addons/uwauv/uwauverror-module.cc b/DESERT_Addons/uwauv/uwauverror-module.cc index 48636dc4..818ca7fa 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.cc +++ b/DESERT_Addons/uwauv/uwauverror-module.cc @@ -80,33 +80,22 @@ UwAUVErrorModule::UwAUVErrorModule() : UwCbrModule() , last_sn_confirmed(0) , sn(0) - , ack(0) - , ackPolicy(ACK_PIGGYBACK) - , ackTimeout(10) - , ackNotPgbk(0) , drop_old_waypoints(1) , log_flag(0) , period(60) , error_m(0) , alarm_mode(0) - , speed(1) + , speed(0.5) , accuracy(0.001) { UWSMEPosition p = UWSMEPosition(); posit=&p; - bind("ackTimeout_", (int*) &ackTimeout); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); bind("log_flag_", (int*) &log_flag ); bind("period_", (int*) &period ); bind("sigma_", (double*) &sigma ); bind("th_ne_", (double*) &th_ne ); bind("accuracy_ne_", (double*) &accuracy ); - if (ackTimeout < 0) { - cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" - << std::endl; - ackTimeout = 10; - } - } @@ -114,20 +103,15 @@ UwAUVErrorModule::UwAUVErrorModule(UWSMEPosition* p) : UwCbrModule() , last_sn_confirmed(0) , sn(0) - , ack(0) - , ackPolicy(ACK_PIGGYBACK) - , ackTimeout(10) - , ackNotPgbk(0) , drop_old_waypoints(1) , log_flag(0) , period(60) , error_m(0) , alarm_mode(0) - , speed(1) + , speed(0.5) , accuracy(0.001) { posit = p; - bind("ackTimeout_", (int*) &ackTimeout); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); bind("log_flag_", (int*) &log_flag ); bind("period_", (int*) &period ); @@ -135,14 +119,6 @@ UwAUVErrorModule::UwAUVErrorModule(UWSMEPosition* p) bind("th_ne_", (double*) &th_ne ); bind("accuracy_ne_", (double*) &accuracy ); - if (ackTimeout < 0) { - cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" - << std::endl; - ackTimeout = 10; - } - - - } UwAUVErrorModule::~UwAUVErrorModule() {} @@ -177,10 +153,6 @@ int UwAUVErrorModule::command(int argc, const char*const* argv) { 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) { @@ -189,24 +161,6 @@ int UwAUVErrorModule::command(int argc, const char*const* argv) { tcl.resultf("%s", "position Setted\n"); return TCL_OK; } - 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; - } - } - if (strcasecmp(argv[1], "setAckTimeout") == 0) { - ackTimeout = atof(argv[2]); - return TCL_OK; - } } else if(argc == 5){ if (strcasecmp(argv[1], "setdest") == 0) { @@ -237,8 +191,6 @@ void UwAUVErrorModule::transmit() { std::cout << NOW << " UwAUVErrorModule::Sending pkt with period: " << period << std::endl; } - - sendTmr_.resched(period); } @@ -247,8 +199,6 @@ void UwAUVErrorModule::initPkt(Packet* p) { hdr_uwcbr *uwcbrh = HDR_UWCBR(p); hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); - uwAUVh->ack() = ack; - ack = 0; uwAUVh->error() = 0; if (alarm_mode != 2 ){ @@ -271,28 +221,27 @@ void UwAUVErrorModule::initPkt(Packet* p) { << "New error, measure: "<< error_m <<", true error: "<< t_e << std::endl; } - if(alarm_mode == 1){ - if (log_flag == 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){ + if (log_flag == 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 + x_e = posit->getX(); // Save error position y_e = posit->getY(); posit->setdest(posit->getXdest(),posit->getYdest(),posit->getZdest(),0); //STOP posit->setAlarm(true); - //alarm_mode = true; uwAUVh->x() = x_e; uwAUVh->y() = y_e; @@ -345,9 +294,6 @@ void UwAUVErrorModule::recv(Packet* p) { hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); - if(uwAUVh->ack() == sn + 1) { - this->p = NULL; - } if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { //obsolete packets @@ -440,25 +386,15 @@ void UwAUVErrorModule::recv(Packet* p) { last_sn_confirmed = uwAUVh->sn(); } - ack = last_sn_confirmed+1; - UwCbrModule::recv(p); - UwCbrModule::sendPkt(); - - - if(uwAUVh->ack() > 0 && debug_) - std::cout << NOW << " UwAUVErrorModule::recv(Packet *p) error ACK " - << "received " << uwAUVh->ack()<< std::endl; - else if((uwAUVh->ack())<0 && debug_) - std::cout << NOW << " UwAUVErrorModule::recv(Packet *p) error NACK " - <<"received"<< std::endl; + //UwCbrModule::sendPkt(); if (log_flag == 1) { out_file_stats.open("log/position_log_a.csv",std::ios_base::app); out_file_stats << NOW << "," << posit->getX() << ","<< posit->getY() - << "," << posit->getZ() << std::endl; + << "," << posit->getZ() << ',' << posit->getSpeed() << std::endl; out_file_stats.close(); } @@ -520,43 +456,9 @@ double UwAUVErrorModule::getErrorMeasure(double t_e){ double m = t_e + noise; - //double p_e = QFunction(m); - - // Calculate the probability using std::erfc - double p_e = std::erfc(((th_ne - m) / std::sqrt(2.0)) / sigma); // prob of t_e grater than th_ne - - - double th_5sig = std::erfc((5*sigma) / std::sqrt(2)) / 2; - - //if (p_e >= th_5sig){ //if p_e is small enough --> no error - // alarm_mode = 1; - //} - - return m; - + return m; } -/*double QFunction(double x) { - - x = (th_ne - x)/ sigma; - - if (x < 0.0) { - return 1.0 - QFunction(-x); // Q(-x) = 1 - Q(x) - } - - double constant = 1.0 / std::sqrt(2.0 * M_PI); - double xSquared = x * x; - double xPower = x; - double qValue = 0.0; - double term = constant * std::exp(-0.5 * xSquared); - - for (int i = 1; i <= 100; i++) { - qValue += term; - term *= -xSquared / i; - } - - return qValue; -}*/ diff --git a/DESERT_Addons/uwauv/uwauverror-module.h b/DESERT_Addons/uwauv/uwauverror-module.h index 190812d0..d586418d 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.h +++ b/DESERT_Addons/uwauv/uwauverror-module.h @@ -180,23 +180,10 @@ class UwAUVErrorModule : public UwCbrModule { protected: - enum UWAUV_ACK_POLICY { ACK_PIGGYBACK, ACK_IMMEDIATELY, ACK_PGBK_OR_TO }; - UWSMEPosition* posit; /**< AUV position.*/ int last_sn_confirmed;/**< Sequence number of the last command Packete received.*/ int sn; - int ack; - //int send_ack_immediately; /**< Flag either to send acks immediately or not.*/ 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.*/ - int ackTimeout; /**< Timeout after which ACK is sent if ackPolicy = ACK_PGBK_OR_TO. */ - 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.*/ From f76bca7bac510949a60d7f6a087da125b46d664a Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Sun, 23 Jul 2023 00:10:02 +0200 Subject: [PATCH 20/36] simulation parameters update --- .../DESERT/samples/desert_samples/AUV/asv.tcl | 13 +++++++------ .../DESERT/samples/desert_samples/AUV/asv_basic.tcl | 2 +- .../DESERT/samples/desert_samples/AUV/auv.tcl | 6 +++--- .../DESERT/samples/desert_samples/AUV/auv_basic.tcl | 6 +++--- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl index 5b5c7092..799df187 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl @@ -10,8 +10,8 @@ proc createASV { id } { 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_ $opt(ctr_period) + 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 @@ -20,16 +20,17 @@ proc createASV { id } { set asv_app($id1) [new Module/UW/AUV/CTR] } - # TRAFFICO 3: ERROR: AUV --> ASV - Module/UW/AUV/CER set packetSize_ $opt(pktsize) - Module/UW/AUV/CER set period_ 60 + # 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 debug_ 1 Module/UW/AUV/CER set log_flag_ 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} { diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv_basic.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv_basic.tcl index 116fe6de..74c6735a 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv_basic.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv_basic.tcl @@ -11,7 +11,7 @@ proc createASV { id } { # TRAFFICO 2: CONTROL: ASV --> AUV Module/UW/AUV/CTR set packetSize_ $opt(pktsize) - Module/UW/AUV/CTR set period_ $opt(ctr_period) + 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 diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl index a81e389c..d62327bd 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl @@ -8,7 +8,7 @@ proc createAUV { id } { # 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(auv_period) + 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 @@ -17,10 +17,10 @@ proc createAUV { id } { # 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_ 60 + 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 debug_ 1 Module/UW/AUV/ERR set log_flag_ 1 Module/UW/AUV/ERR set sigma_ $opt(variance) Module/UW/AUV/ERR set th_ne_ [expr 1 - $opt(e_prob)] diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv_basic.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv_basic.tcl index 275c5fbd..50725282 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv_basic.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv_basic.tcl @@ -7,8 +7,8 @@ proc createAUV { id } { # 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(auv_period) + 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 @@ -17,7 +17,7 @@ proc createAUV { id } { # TRAFFICO 3: ERROR AUV --> ASV set node_auv($id) [$ns create-M_Node $opt(tracefile) $opt(cltracefile)] Module/UW/AUV/ERB set packetSize_ $opt(pktsize) - Module/UW/AUV/ERB set period_ 60 + Module/UW/AUV/ERB set period_ $opt(period) Module/UW/AUV/ERB set PoissonTraffic_ 0 Module/UW/AUV/ERB set traffic_type_ 3 Module/UW/AUV/ERB set debug_ 0 From 97c9eba7bf0d98091a99ea77a83880462734fd6f Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Sun, 23 Jul 2023 00:10:48 +0200 Subject: [PATCH 21/36] power computation --- .../samples/desert_samples/AUV/metric_comp.py | 31 +- .../desert_samples/AUV/metric_comp_4.py | 34 +- .../desert_samples/AUV/plot_coordinates.py | 73 +++- .../AUV/plot_error_evolution.py | 17 +- .../desert_samples/AUV/result_compute.py | 363 ++++++++++-------- .../samples/desert_samples/AUV/sim_banch.sh | 78 ++++ .../samples/desert_samples/AUV/sim_err.sh | 76 ++++ .../desert_samples/AUV/test_uwauv_error.tcl | 189 ++++----- .../AUV/test_uwauv_error_basic.tcl | 204 ++++------ 9 files changed, 649 insertions(+), 416 deletions(-) create mode 100755 DESERT_Framework/DESERT/samples/desert_samples/AUV/sim_banch.sh create mode 100755 DESERT_Framework/DESERT/samples/desert_samples/AUV/sim_err.sh diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/metric_comp.py b/DESERT_Framework/DESERT/samples/desert_samples/AUV/metric_comp.py index ca16ab67..ed8d7666 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/metric_comp.py +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/metric_comp.py @@ -28,15 +28,28 @@ 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): + if (float(row[1]) < 0 and float(row[2]) > 0): #1Q -> auv_1 auv_1.append((float(row[1]),float(row[2]))) - else: + 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 + 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 = [] @@ -152,18 +165,24 @@ def separate_rows(filename): total_distance = calculate_total_distance(pos_sv) if os.path.exists(log_position_a): - auv_1,auv_2 = plot_auv_coordinates_log(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) - -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,'\n') # time spent in error distance +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 index 2abfe69b..f5e8e82c 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/metric_comp_4.py +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/metric_comp_4.py @@ -4,6 +4,13 @@ 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 @@ -13,6 +20,7 @@ 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 @@ -20,15 +28,22 @@ 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): + if (float(row[1]) < 0 and float(row[2]) > 0): #1Q -> auv_1 auv_1.append((float(row[1]),float(row[2]))) - else: + 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 - return auv_1,auv_2 def plot_coordinates_log(file_path): @@ -140,19 +155,24 @@ def separate_rows(filename): total_distance = calculate_total_distance(pos_sv) if os.path.exists(log_position_a): - auv_1,auv_2 = plot_auv_coordinates_log(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) - - -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,'\n') # time spent in error distance +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 diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_coordinates.py b/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_coordinates.py index 402d6534..5dbf2d72 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_coordinates.py +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_coordinates.py @@ -1,5 +1,7 @@ import csv import matplotlib.pyplot as plt +import tikzplotlib + def plot_coordinates(file_path,x,y,t): @@ -10,13 +12,30 @@ def plot_coordinates(file_path,x,y,t): y.append(float(row[2])) t.append(float(row[0])) -def plot_coordinates_log(file_path,x,y): - +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: - x.append(float(row[1])) - y.append(float(row[2])) + 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): @@ -42,7 +61,7 @@ def plot_movement_log(file_path,t,axis): Y_1 = [] Z_1 = [] file_path = 'log/position_log_a.csv' # Replace with your file pathplot_coordinates(file_path) -plot_coordinates_log(file_path,X_1,Y_1) +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) @@ -77,11 +96,49 @@ def plot_movement_log(file_path,t,axis): 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]) fig = plt.figure() ax = plt.subplot() -ax.plot(X_1, Y_1,'ko', label='auv_1') +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') @@ -89,4 +146,6 @@ def plot_movement_log(file_path,t,axis): ax.set_ylabel('Y') ax.legend() #ax.set_zlabel('Z') -plt.show() \ No newline at end of file +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 index 7c335620..3da621a9 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_error_evolution.py +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_error_evolution.py @@ -99,6 +99,8 @@ def separate_rows(filename): 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] @@ -127,7 +129,7 @@ def separate_rows(filename): ax.legend() plt.show() -error_g, error_r = separate_rows(log_error) +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] @@ -152,12 +154,13 @@ def separate_rows(filename): fig = plt.figure() ax = plt.subplot() -ax.plot(x_c, y_c,'g--', label='sv') -ax.plot(x_a, y_a,'m.', label='sv') -ax.plot(g_on_x, g_on_y,'ko', label='g_error_on') -ax.plot(g_off_x, g_off_y,'kx', label='g_error_off') -ax.plot(r_on_x, r_on_y,'ro', label='r_error_on') -ax.plot(r_off_x,r_off_y,'rx', label='r_error_off') +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 index 003d14d2..a960f89b 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/result_compute.py +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/result_compute.py @@ -3,10 +3,22 @@ from scipy import stats import seaborn as sns import pandas as pd - -def compute_error(file_path): +import tikzplotlib + +def compute_power(): + v = 1.5 + Cd = 11.3 + A = 0.0048 + a_dens = 1025 + 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={} @@ -17,7 +29,15 @@ def compute_error(file_path): 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(';') @@ -26,13 +46,19 @@ def compute_error(file_path): if float(row[0]) not in m_t: if float(row[10]): m_t[float(row[0])]=[float(row[4])/float(row[10])] - m_d[float(row[0])]=[float(row[5])/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])] - m_d[float(row[0])]=[float(row[5])] + 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])] @@ -46,32 +72,92 @@ def compute_error(file_path): 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]): - rc[float(row[0])]=[float(row[6])/(float(row[6])+float(row[7]))] + 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*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])) - m_d[float(row[0])].append(float(row[5])/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])) - m_d[float(row[0])].append(float(row[5])) + 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])) + 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*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: m_tp[float(row[0])].append(float(row[6])) if float(row[6])+float(row[9]): - pr[float(row[0])].append(float(row[6])/(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])+float(row[7]): - rc[float(row[0])].append(float(row[6])/(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]): @@ -82,18 +168,25 @@ def compute_error(file_path): 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 + 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 file_path = "result.csv" -m1_t,m1_d,m1_tp,m1_fp,m1_tn,m1_fn,acc1,pr1,rc1, d11,d12 = compute_error(file_path) +m1_t,m1_d,m1_tp,m1_fp,m1_tn,m1_fn,acc1,pr1,rc1, d11,d12,d13,d14, asv_e, auv_e = 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 = compute_error(file_path) +m2_t,m2_d,m2_tp,m2_fp,m2_tn,m2_fn,acc2,pr2,rc2,d21,d22,d23,d24,asv_e2, auv_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]) + +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]) pr1 = {'Key':pr1.keys(), 'Values':pr1.values()} @@ -103,24 +196,25 @@ def compute_error(file_path): pr1 = pr1.explode('Values') pr1 = pr1.reset_index(drop=True) pr1.columns= ['Key','Values'] -sns.lineplot(data=pr1,x='Key',y='Values',markers=True,label='smart') +sns.lineplot(data=pr1,x='Key',y='Values',marker='o',label='IER') pr2 = {'Key':pr2.keys(), - 'Values':pr2.values()} + 'Values':pr2.values()} pr2 = pd.DataFrame(pr2) pr2 = pr2.explode('Values') pr2 = pr2.reset_index(drop=True) pr2.columns= ['Key','Values'] -print(pr2['Key']) -sns.lineplot(data=pr2,x='Key',y='Values',markers=True,label='basic') +sns.lineplot(data=pr2,x='Key',y='Values',marker='^',markersize='8',label='SER') plt.title('Precision') +plt.ylim(bottom=0,top=1) plt.xscale('log') -plt.grid() -plt.xlabel('Accuracy') -ax.legend() +plt.grid(True, linestyle='dashed', linewidth=0.5, color='gray',axis='y',which='both') +plt.xlabel('$\epsilon$') plt.show() +#tikzplotlib.save('pr.tex') +plt.close() rc1 = {'Key':rc1.keys(), @@ -131,7 +225,7 @@ def compute_error(file_path): rc1 = rc1.explode('Values') rc1 = rc1.reset_index(drop=True) rc1.columns= ['Key','Values'] -sns.lineplot(data=rc1,x='Key',y='Values',markers='o',label='smart') +sns.lineplot(data=rc1,x='Key',y='Values',marker='o',label='IER') rc2 = {'Key':rc2.keys(), 'Values':rc2.values()} @@ -140,113 +234,18 @@ def compute_error(file_path): rc2 = rc2.explode('Values') rc2 = rc2.reset_index(drop=True) rc2.columns= ['Key','Values'] -sns.lineplot(data=rc2,x='Key',y='Values',markers='o',label='basic') +sns.lineplot(data=rc2,x='Key',y='Values',marker='^',markersize='8',label='SER') +plt.ylim(bottom=0) plt.title('Recall') plt.xscale('log') -plt.grid() -plt.xlabel('Accuracy') -ax.legend() +plt.grid(True, linestyle='dashed', linewidth=0.5, color='gray',axis='y',which='both') +plt.xlabel('$\epsilon$') plt.show() +#tikzplotlib.save('rec.tex') +plt.close() -# m1_tp = {'Key':m1_t.keys(), -# 'Values':m1_tp.values()} -# m1_tp = pd.DataFrame(m1_tp) - -# ax = plt.figure() -# m1_tp = m1_tp.explode('Values') -# m1_tp = m1_tp.reset_index(drop=True) -# m1_tp.columns= ['Key','Values'] -# sns.lineplot(data=m1_tp,x='Key',y='Values',label='smart') - -# m2_tp = {'Key':m2_t.keys(), -# 'Values':m2_tp.values()} -# tp_df = pd.DataFrame(m2_tp) -# 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',label='basic') - -# plt.title('True positive') -# plt.xscale('log') -# plt.grid() -# plt.xlabel('Accuracy') -# ax.legend() -# plt.show() - -# plt.figure() -# #plt.errorbar(m_fp.keys(),mean_fp,yerr=ci_fp,label='fp',fmt='o',color='#1f77b4') -# #plt.plot(m_fp.keys(),mean_fp,'o--',color='#1f77b4') -# data = {'Key':m1_t.keys(), -# 'Values':m1_fp.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',label='smart') - -# data = {'Key':m2_t.keys(), -# 'Values':m2_fp.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',label='basic') -# plt.xscale('log') -# plt.grid() -# plt.title('False positive') -# plt.xlabel('Accuracy') -# plt.show() - -# plt.figure() -# #plt.errorbar(m_fn.keys(),mean_fn,yerr=ci_fn,label='fn',fmt='o',color='#1f77b4') -# #plt.plot(m_fn.keys(),mean_fn,'^--',color='#1f77b4') -# data = {'Key':m1_t.keys(), -# 'Values':m1_fn.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',label='smart') -# data = {'Key':m2_t.keys(), -# 'Values':m2_fn.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',label='basic') -# plt.grid() -# plt.xscale('log') -# plt.title('False negative') -# plt.xlabel('Accuracy') -# plt.show() - -# plt.figure() -# #plt.errorbar(m_tn.keys(),mean_tn,yerr=ci_tn,label='tn',fmt='o',color='#1f77b4') -# #plt.plot(m_tn.keys(),mean_tn,'^--',color='#1f77b4') -# data = {'Key':m1_t.keys(), -# 'Values':m1_tn.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',label='smart') - -# data = {'Key':m2_t.keys(), -# 'Values':m2_tn.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',label='basic') - -# plt.xscale('log') -# plt.title('True negative') -# plt.xlabel('Accuracy') -# plt.grid() -# plt.show() - 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') @@ -256,7 +255,7 @@ def compute_error(file_path): 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',label='smart') +sns.lineplot(data=tp_df,x='Key',y='Values',marker='o',label='IER') data = {'Key':m2_t.keys(), 'Values':m2_d.values()} @@ -264,78 +263,136 @@ def compute_error(file_path): 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',label='basic') +sns.lineplot(data=tp_df,x='Key',y='Values',marker='^',markersize='8',label='SER') -ax.legend() plt.xscale('log') -plt.yscale('log') -plt.xlabel('Accuracy') -plt.ylabel('Distance') -plt.grid() +#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.title('ASV\'s Distance Traveled') +plt.title('ASV\'s Energy Consumption (movement) per Error') plt.show() +#tikzplotlib.save('energy.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') +#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_t.values()} + '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',label='smart') +sns.lineplot(data=tp_df,x='Key',y='Values',marker='o',label='IER') data = {'Key':m2_t.keys(), - 'Values':m2_t.values()} + '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',label='basic') -ax.legend() +sns.lineplot(data=tp_df,x='Key',y='Values',marker='^',markersize='8',label='SER') + plt.xscale('log') -plt.yscale('log') -plt.xlabel('Accuracy') -plt.ylabel('Time') +#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.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.tex') +plt.close() -data = {'Key':d11.keys(), - 'Values':d11.values()} +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',label='smart_1') +sns.lineplot(data=tp_df,x='Key',y='Values',marker='o',label='IER') -data = {'Key':d12.keys(), - 'Values':d12.values()} +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',label='smart_2') +sns.lineplot(data=tp_df,x='Key',y='Values',marker='^',markersize='8',label='SER') -data = {'Key':d21.keys(), - 'Values':d21.values()} +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.title('ASV\'s Distance Traveled') +#plt.ylim((10,100)) +plt.title('AUV\'s Energy Consumption (tx)') +plt.show() +#tikzplotlib.save('energy.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',label='basic_1') +sns.lineplot(data=tp_df,x='Key',y='Values',marker='o',label='IER') -data = {'Key':d22.keys(), - 'Values':d22.values()} +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',label='basic_2') +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('Time') +plt.title('Average Downtime per Error') +plt.show() +#tikzplotlib.save('time.tex') +plt.close() + +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') + -ax.legend() plt.xscale('log') plt.yscale('log') -plt.xlabel('Accuracy') -plt.ylabel('Distance covered') +plt.grid(True, linestyle='dashed', linewidth=0.5, color='gray',axis='y',which='both') +plt.xlabel('$\epsilon$') +plt.ylabel('Distance') +plt.title('AUV\'s Distance Covered') plt.show() +#tikzplotlib.save('dist.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 index c080b29c..a39e7807 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwauv_error.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwauv_error.tcl @@ -26,7 +26,7 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # -# Author: Giovanni Toso +# Author: Alessia Ortile # Version: 1.0.0 # NOTE: tcl sample tested on Ubuntu 12.04, 64 bits OS # @@ -125,39 +125,23 @@ $ns use-Miracle ################## # Tcl variables # ################## -set opt(n_auv) 2 ;# Number of Nodes +set opt(n_auv) 4 ;# Number of Nodes set opt(starttime) 1 set opt(stoptime) 150000 set opt(txduration) [expr $opt(stoptime) - $opt(starttime)] set opt(rngstream) 1 set opt(maxinterval_) 20.0 -set opt(freq) 25000.0 -set opt(bw) 5000.0 -#set opt(freq_hf) 60000.0 -#set opt(bw_hf) 10000.0 +set opt(freq) 20000.0 +set opt(bw) 10000.0 set opt(bitrate) 4800.0 -#set opt(bitrate_hf) 64000.0 set opt(ack_mode) "setNoAckMode" -set opt(txpower) 135.0 -#set opt(txpower_hf) 135.0 - -#set opt(tdma_frame) 20 -#set opt(tdma_gard) 1 - +set opt(txpower) 175.0 set opt(pktsize) 125 -set opt(ctr_period) 60 - -set opt(pktsize_monitoring) 125 -set opt(auv_period) 60 - -#set opt(pktsize_control) 100 -#set opt(cbr_period_control) [expr $opt(cbr_period_monitoring)*4] - -set opt(pktsize_error) 100 -set opt(auv_period_error) 60 +set opt(pktsize_monitoring) 5 +set opt(period) 60 set opt(op_freq) 10000000 set opt(op_bw) 100000 @@ -222,6 +206,12 @@ if {$opt(trace_files)} { } 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) @@ -230,20 +220,6 @@ $data_mask setBandwidth $opt(bw) ######################### # Module Configuration # ######################### -#UW/AUV -Module/UW/AUV set packetSize_ $opt(pktsize) -Module/UW/AUV set period_ $opt(auv_period) -Module/UW/AUV set PoissonTraffic_ 1 -Module/UW/AUV set debug_ 0 - -# BPSK -Module/MPhy/BPSK set BitRate_ $opt(bitrate) -Module/MPhy/BPSK set TxPower_ $opt(txpower) - -#FLOODING -Module/UW/FLOODING set ttl_ 2 -Module/UW/FLOODING set maximum_cache_time__time_ $opt(stoptime) - Module/UW/IP set debug_ 0 Module/UW/UDP set debug_ 0 @@ -358,18 +334,29 @@ 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/UWSME debug_ 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/UWSME"] - $position_auv($id) setX_ 1*($id*(2))-1 - $position_auv($id) setY_ 1*($id*(-2))-1 $position_auv($id) setZ_ -1000 $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_]" + #puts "x = [$position_auv($id) getX_]; y = [$position_auv($id) getY_]; z = [$position_auv($id) getZ_]" } @@ -393,9 +380,13 @@ set data [split $file_data "\n"] foreach line $data { if {[regexp {^(.*),(.*),(.*),(.*)$} $line -> t x y z]} { $ns at $t "update_and_check $t" - 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]" - } + $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]" + #} } } @@ -441,10 +432,6 @@ proc update_and_check {t} { close $outfile_auv close $outfile_asv - if {[$auv_app(0) getX] == -510.0 && [$auv_app(0) getY] == 510.0 && [$auv_app(1) getX] == 510.0 && [$auv_app(1) getY] == -510.0} { - puts "STOP" - ns "finish; $ns halt" - } } @@ -463,88 +450,60 @@ proc finish {} { 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 - puts "---------------------------------------------------------------------" - #puts "Simulation summary" - #puts "Leader addr = [$ipif_asv addr]" - #for {set i 0} {$i < $opt(n_auv)} {incr i} { - # puts "Diver addr = [$ipif_auv($i) addr]" - # #puts "Packets in buffer [$mac_auv($i) get_buffer_size]" - #} - #puts "number of divers : $opt(n_auv)" - #puts "simulation length: $opt(txduration) s" - #puts "---------------------------------------------------------------------" - - set sum_cbr_throughput 0 - set sum_cbr_sent_pkts 0.0 - set sum_cbr_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_cbr_throughput2 0 - set sum_cbr_sent_pkts2 0.0 - set sum_cbr_rcv_pkts2 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_cbr_throughput3 0 - set sum_cbr_sent_pkts3 0.0 - set sum_cbr_rcv_pkts3 0.0 - - set sum_cbr_throughput4 0 - set sum_cbr_sent_pkts4 0.0 - set sum_cbr_rcv_pkts4 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 cbr_throughput [$asv_app($i) getthr] - set cbr_sent_pkts [$auv_app($i) getsentpkts] - set cbr_rcv_pkts [$asv_app($i) getrecvpkts] + 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 cbr_throughput2 [$auv_app($i) getthr] - set cbr_sent_pkts2 [$asv_app($i) getsentpkts] - set cbr_rcv_pkts2 [$auv_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 cbr_throughput4 [$asv_err($i) getthr] - set cbr_sent_pkts4 [$auv_err($i) getsentpkts] - set cbr_rcv_pkts4 [$asv_err($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 sum_cbr_throughput [expr $sum_cbr_throughput + $cbr_throughput] - set sum_cbr_sent_pkts [expr $sum_cbr_sent_pkts + $cbr_sent_pkts] - set sum_cbr_rcv_pkts [expr $sum_cbr_rcv_pkts + $cbr_rcv_pkts] + 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_cbr_throughput2 [expr $sum_cbr_throughput2 + $cbr_throughput2] - set sum_cbr_sent_pkts2 [expr $sum_cbr_sent_pkts2 + $cbr_sent_pkts2] - set sum_cbr_rcv_pkts2 [expr $sum_cbr_rcv_pkts2 + $cbr_rcv_pkts2] + 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_cbr_throughput4 [expr $sum_cbr_throughput4 + $cbr_throughput4] - set sum_cbr_sent_pkts4 [expr $sum_cbr_sent_pkts4 + $cbr_sent_pkts4] - set sum_cbr_rcv_pkts4 [expr $sum_cbr_rcv_pkts4 + $cbr_rcv_pkts4] - } + 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 ipheadersize [$ipif_asv getipheadersize] - set udpheadersize [$udp_asv getudpheadersize] - set cbrheadersize [$asv_app(0) getcbrheadersize] + 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 "IP Pkt Header Size : $ipheadersize" - #puts "UDP Header Size : $udpheadersize" - #puts "CBR Header Size : $cbrheadersize" + 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" + - #puts "Traffic MONITORING ---------------------------------------------" - #puts "Mean Throughput : [expr ($sum_cbr_throughput/(1+$opt(n_auv)))]" - #puts "Sent Packets : $sum_cbr_sent_pkts" - #puts "Received Packets : $sum_cbr_rcv_pkts" - #puts "Packet Delivery Ratio : [expr $sum_cbr_rcv_pkts / $sum_cbr_sent_pkts * 100]" - - #puts "Traffic CONTROL ---------------------------------------------" - #puts "Mean Throughput : [expr ($sum_cbr_throughput2/($opt(n_auv)))]" - #puts "Sent Packets : $sum_cbr_sent_pkts2" - #puts "Received Packets : $sum_cbr_rcv_pkts2" - #puts "Packet Delivery Ratio : [expr $sum_cbr_rcv_pkts2 / $sum_cbr_sent_pkts2 * 100]" - - #puts "Traffic ERROR ---------------------------------------------" - #puts "Mean Throughput : [expr ($sum_cbr_throughput4/($opt(n_auv)))]" - #puts "Sent Packets : $sum_cbr_sent_pkts4" - #puts "Received Packets : $sum_cbr_rcv_pkts4" - #puts "Packet Delivery Ratio : [expr $sum_cbr_rcv_pkts4 / $sum_cbr_sent_pkts4 * 100]" - $ns flush-trace close $opt(tracefile) } 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 index b1207dbd..30f239fb 100644 --- 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 @@ -102,8 +102,6 @@ load libuwphy_clmsgs.so load libuwstats_utilities.so load libuwphysical.so load libuwposbasedrt.so -#load libuwnoderep.so; #non riesco ad importarla -#load libuwsecurity_clmsg.so; #non riesco ad importarla load libuwflooding.so load libuwinterference.so load libuwphy_clmsgs.so @@ -125,45 +123,31 @@ $ns use-Miracle ################## # Tcl variables # ################## -set opt(n_auv) 2 ;# Number of Nodes +set opt(n_auv) 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) 25000.0 -set opt(bw) 5000.0 -#set opt(freq_hf) 60000.0 -#set opt(bw_hf) 10000.0 +set opt(freq) 20000.0 +set opt(bw) 10000.0 set opt(bitrate) 4800.0 -#set opt(bitrate_hf) 64000.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(txpower) 135.0 -#set opt(txpower_hf) 135.0 - -#set opt(tdma_frame) 20 -#set opt(tdma_gard) 1 - -set opt(pktsize) 125 -set opt(ctr_period) 60 - -set opt(pktsize_monitoring) 125 -set opt(auv_period) 60 - -#set opt(pktsize_control) 100 -#set opt(cbr_period_control) [expr $opt(cbr_period_monitoring)*4] - -set opt(pktsize_error) 100 -set opt(auv_period_error) 60 -set opt(op_freq) 10000000 -set opt(op_bw) 100000 -set opt(bitrate_op) 1000000 -set opt(txpower_op) 30 -set opt(acq_db_op) 10 +set opt(op_freq) 10000000 +set opt(op_bw) 100000 +set opt(bitrate_op) 1000000 +set opt(txpower_op) 30 +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 @@ -174,12 +158,8 @@ 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(rngstream) 13 -#set opt(ctr_period) 60 if {$opt(bash_parameters)} { if {$argc != 4} { @@ -221,8 +201,14 @@ if {$opt(trace_files)} { 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 channel [new Module/UnderwaterChannel] set data_mask [new MSpectralMask/Rect] $data_mask setFreq $opt(freq) $data_mask setBandwidth $opt(bw) @@ -230,20 +216,6 @@ $data_mask setBandwidth $opt(bw) ######################### # Module Configuration # ######################### -#UW/AUV -Module/UW/AUV set packetSize_ $opt(pktsize) -Module/UW/AUV set period_ $opt(auv_period) -Module/UW/AUV set PoissonTraffic_ 1 -Module/UW/AUV set debug_ 0 - -# BPSK -Module/MPhy/BPSK set BitRate_ $opt(bitrate) -Module/MPhy/BPSK set TxPower_ $opt(txpower) - -#FLOODING -Module/UW/FLOODING set ttl_ 2 -Module/UW/FLOODING set maximum_cache_time__time_ $opt(stoptime) - Module/UW/IP set debug_ 0 Module/UW/UDP set debug_ 0 @@ -358,18 +330,29 @@ 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/UWSME debug_ 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/UWSME"] - $position_auv($id) setX_ 1*($id*(2))-1 - $position_auv($id) setY_ 1*($id*(-2))-1 $position_auv($id) setZ_ -1000 $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_]" + #puts "x = [$position_auv($id) getX_]; y = [$position_auv($id) getY_]; z = [$position_auv($id) getZ_]" } @@ -393,9 +376,14 @@ set data [split $file_data "\n"] foreach line $data { if {[regexp {^(.*),(.*),(.*),(.*)$} $line -> t x y z]} { $ns at $t "update_and_check $t" - 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]" - } + $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]" + #} } } @@ -459,88 +447,62 @@ proc finish {} { 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 - puts "---------------------------------------------------------------------" - puts "Simulation summary" - puts "Leader addr = [$ipif_asv addr]" - for {set i 0} {$i < $opt(n_auv)} {incr i} { - puts "Diver addr = [$ipif_auv($i) addr]" - #puts "Packets in buffer [$mac_auv($i) get_buffer_size]" - } - puts "number of divers : $opt(n_auv)" - puts "simulation length: $opt(txduration) s" - puts "---------------------------------------------------------------------" + set sum_auv_mon_throughput 0 + set sum_auv_mon_sent_pkts 0.0 + set sum_auv_mon_rcv_pkts 0.0 - set sum_cbr_throughput 0 - set sum_cbr_sent_pkts 0.0 - set sum_cbr_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_cbr_throughput2 0 - set sum_cbr_sent_pkts2 0.0 - set sum_cbr_rcv_pkts2 0.0 + set sum_auv_err_throughput 0 + set sum_auv_err_sent_pkts 0.0 + set sum_auv_err_rcv_pkts 0.0 - set sum_cbr_throughput3 0 - set sum_cbr_sent_pkts3 0.0 - set sum_cbr_rcv_pkts3 0.0 - set sum_cbr_throughput4 0 - set sum_cbr_sent_pkts4 0.0 - set sum_cbr_rcv_pkts4 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] - for {set i 0} {$i < $opt(n_auv)} {incr i} { - set cbr_throughput [$asv_app($i) getthr] - set cbr_sent_pkts [$auv_app($i) getsentpkts] - set cbr_rcv_pkts [$asv_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 cbr_throughput2 [$auv_app($i) getthr] - set cbr_sent_pkts2 [$asv_app($i) getsentpkts] - set cbr_rcv_pkts2 [$auv_app($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 cbr_throughput4 [$asv_err($i) getthr] - set cbr_sent_pkts4 [$auv_err($i) getsentpkts] - set cbr_rcv_pkts4 [$asv_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_cbr_throughput [expr $sum_cbr_throughput + $cbr_throughput] - set sum_cbr_sent_pkts [expr $sum_cbr_sent_pkts + $cbr_sent_pkts] - set sum_cbr_rcv_pkts [expr $sum_cbr_rcv_pkts + $cbr_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_cbr_throughput2 [expr $sum_cbr_throughput2 + $cbr_throughput2] - set sum_cbr_sent_pkts2 [expr $sum_cbr_sent_pkts2 + $cbr_sent_pkts2] - set sum_cbr_rcv_pkts2 [expr $sum_cbr_rcv_pkts2 + $cbr_rcv_pkts2] + 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_cbr_throughput4 [expr $sum_cbr_throughput4 + $cbr_throughput4] - set sum_cbr_sent_pkts4 [expr $sum_cbr_sent_pkts4 + $cbr_sent_pkts4] - set sum_cbr_rcv_pkts4 [expr $sum_cbr_rcv_pkts4 + $cbr_rcv_pkts4] + 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 "IP Pkt Header Size : $ipheadersize" - puts "UDP Header Size : $udpheadersize" - puts "CBR Header Size : $cbrheadersize" - - puts "Traffic MONITORING ---------------------------------------------" - puts "Mean Throughput : [expr ($sum_cbr_throughput/(1+$opt(n_auv)))]" - puts "Sent Packets : $sum_cbr_sent_pkts" - puts "Received Packets : $sum_cbr_rcv_pkts" - puts "Packet Delivery Ratio : [expr $sum_cbr_rcv_pkts / $sum_cbr_sent_pkts * 100]" - - puts "Traffic CONTROL ---------------------------------------------" - puts "Mean Throughput : [expr ($sum_cbr_throughput2/($opt(n_auv)))]" - puts "Sent Packets : $sum_cbr_sent_pkts2" - puts "Received Packets : $sum_cbr_rcv_pkts2" - puts "Packet Delivery Ratio : [expr $sum_cbr_rcv_pkts2 / $sum_cbr_sent_pkts2 * 100]" - - puts "Traffic ERROR ---------------------------------------------" - puts "Mean Throughput : [expr ($sum_cbr_throughput4/($opt(n_auv)))]" - puts "Sent Packets : $sum_cbr_sent_pkts4" - puts "Received Packets : $sum_cbr_rcv_pkts4" - puts "Packet Delivery Ratio : [expr $sum_cbr_rcv_pkts4 / $sum_cbr_sent_pkts4 * 100]" - + 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) } From 61cc8ad1c55c2922e46a0322d86709c164837bef Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Mon, 28 Aug 2023 15:26:30 +0200 Subject: [PATCH 22/36] tp counter correction + last err correction --- DESERT_Addons/uwauv/uwauvctrer-module.cc | 131 +++++++------- DESERT_Addons/uwauv/uwauvctrer-module.h | 2 + DESERT_Addons/uwauv/uwauverror-b-module.cc | 20 +-- DESERT_Addons/uwauv/uwauverror-b-module.h | 1 - DESERT_Addons/uwauv/uwauverror-module.cc | 65 ++++--- DESERT_Addons/uwauv/uwauverror-module.h | 2 - .../samples/desert_samples/AUV/metric_comp.py | 4 +- .../desert_samples/AUV/metric_comp_4.py | 3 + .../desert_samples/AUV/plot_coordinates.py | 17 +- .../desert_samples/AUV/result_compute.py | 168 +++++++++++------- 10 files changed, 219 insertions(+), 194 deletions(-) diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.cc b/DESERT_Addons/uwauv/uwauvctrer-module.cc index bb8bbb9e..b5562c6d 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.cc +++ b/DESERT_Addons/uwauv/uwauvctrer-module.cc @@ -216,14 +216,6 @@ void UwAUVCtrErModule::initPkt(Packet* p) { error_released = false; this->p = p; - if (log_flag == 1) { - - err_log.open("log/error_log_t.csv",std::ios_base::app); - err_log << "G,"<< NOW << "," << x_s<<","<error() = -1; + uwAUVh->error() = -2; alarm_mode = 0; uwAUVh->sn() = ++sn; uwAUVh->x() = x_s; @@ -283,7 +275,7 @@ void UwAUVCtrErModule::initPkt(Packet* p) { << std::endl; } - if (!alarm_queue.empty()){ //take care of the next error + /*if (!alarm_queue.empty()){ //take care of the next error x_err = alarm_queue[0][0]; y_err = alarm_queue[0][1]; @@ -297,16 +289,16 @@ void UwAUVCtrErModule::initPkt(Packet* p) { y_sorg = posit->getY(); if (debug_) { - std::cout << NOW << " UwAUVCtrErrModule::initPkt(Packet *p) SV picked a new " + std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) SV picked a new " "error from the queue: X = " << x_err << ", Y = " << y_err<< std::endl; } - } + }*/ }else{ uwAUVh->error() = 1; - uwAUVh->sn() = sn; + uwAUVh->sn() = ++sn; //++ or no? uwAUVh->x() = x_err; uwAUVh->y() = y_err; this->p = p; @@ -319,19 +311,8 @@ void UwAUVCtrErModule::initPkt(Packet* p) { } } - - if (debug_) { - std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) ACK recv" - << std::endl; - } - UwCbrModule::initPkt(p); - if (debug_) { - std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) setting last ack" - << std::endl; - } - } void UwAUVCtrErModule::recv(Packet* p, Handler* h) { @@ -341,16 +322,13 @@ void UwAUVCtrErModule::recv(Packet* p, Handler* h) { void UwAUVCtrErModule::recv(Packet* p) { hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); - if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { //obsolete packets 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_) @@ -358,27 +336,27 @@ void UwAUVCtrErModule::recv(Packet* p) { }else{ // error of some kind - int status = checkError(uwAUVh->error(),1, uwAUVh->x(), uwAUVh->y()); + 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; - // Itera su ciascun vettore interno di gray_queue + + int i=0; for (const auto& vec : gray_queue) { - // Controlla se le coordinate corrispondono if (vec[0] == uwAUVh->x() && vec[1] == uwAUVh->y()) { exists = true; break; } - i++; } if(exists){ if (debug_) - std::cout << NOW << " UwAUVCtrErrModule::recv(Pakct p) gray_queue error value updated, old error("<< (gray_queue[i][2]/gray_queue[i][3]) << "),"; + 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; @@ -395,6 +373,7 @@ void UwAUVCtrErModule::recv(Packet* p) { 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; @@ -405,6 +384,15 @@ void UwAUVCtrErModule::recv(Packet* p) { } 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){ @@ -417,23 +405,18 @@ void UwAUVCtrErModule::recv(Packet* p) { y_sorg = posit->getY(); posit->setdest(x_err,y_err,posit->getZ(),speed); - - alarm_mode = status; + alarm_mode = 2; 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_flag == 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 (log_flag == 1) { err_log.open("log/error_log_t.csv",std::ios_base::app); err_log << "R,"<< NOW << "," << x_err <<","<setdest(x_err,y_err,posit->getZ(),speed); + exists=false; - alarm_mode = status; - - x_sorg = posit->getX(); - y_sorg = posit->getY(); + for (const auto& vec : rcv_queue) { + if (vec[0] == alarm_queue[0][0] && vec[1] == alarm_queue[0][1]) { //next error is associated to this app + exists = true; + break; + } + } - exists = false; + if(exists){ + + x_err = alarm_queue[0][0]; + y_err = alarm_queue[0][1]; + posit->setdest(x_err,y_err,posit->getZ(),speed); + alarm_mode = 2; + + x_sorg = posit->getX(); + y_sorg = posit->getY(); + + alarm_queue.erase(alarm_queue.begin()); + + }else{ + alarm_mode = 3; + //wait another app to take care of it + } + + + exists = false; for (const auto& vec : alarm_queue) { - // Controlla se le coordinate corrispondono if (vec[0] == uwAUVh->x() && vec[1] == uwAUVh->y()) { exists = true; break; @@ -469,7 +469,7 @@ void UwAUVCtrErModule::recv(Packet* p) { } } - alarm_queue.erase(alarm_queue.begin()); + if (log_flag == 1) { @@ -492,7 +492,6 @@ void UwAUVCtrErModule::recv(Packet* p) { exists = false; for (const auto& vec : alarm_queue) { - // Controlla se le coordinate corrispondono if (vec[0] == uwAUVh->x() && vec[1] == uwAUVh->y()) { exists = true; break; @@ -516,7 +515,15 @@ void UwAUVCtrErModule::recv(Packet* p) { }else{ - //delete point in gray_queue + //status 0 --> no error + 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; + } + } + error_released = true; x_s = uwAUVh->x(); y_s = uwAUVh->y(); @@ -542,30 +549,14 @@ void UwAUVCtrErModule::recv(Packet* p) { int UwAUVCtrErModule::checkError(double m, int n_pkt, float x, float y){ - // Calculate the probability using std::erfc - double p_e = std::erfc(((th_ne - (m/n_pkt)) * std::sqrt(n_pkt) / std::sqrt(2.0)) / sigma); // prob of true error (t_e) greater than th_ne - //double th_5sig = std::erfc((5*sigma) / std::sqrt(2)) / 2; + double p_e = std::erfc((((th_ne - (m/n_pkt)) * std::sqrt(n_pkt)) / std::sqrt(2.0)) / sigma)/2; // prob of true error (t_e) greater than th_ne int status; - - if (p_e <= accuracy){ //if p_e is small enough --> no error - // NO ERROR - /*if (log_flag == 1) { - t_err_log.open("log/true_error_log.csv",std::ios_base::app); - t_err_log << NOW << "," << x <<","<< y <<","<< 0 << std::endl; - t_err_log.close(); - }*/ + if (p_e < accuracy){ //if p_e is small enough --> no error status = 0; }else if (p_e > (1-accuracy)){ // FOR SURE ERROR status = 2; - - /*if (log_flag == 1) { - t_err_log.open("log/true_error_log.csv",std::ios_base::app); - t_err_log << NOW << "," << x <<","<< y <<","<< 1 << std::endl; - t_err_log.close(); - }*/ - }else{ //I NEED MORE DATA status = 1; diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.h b/DESERT_Addons/uwauv/uwauvctrer-module.h index 04c81ad6..6e3d267c 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.h +++ b/DESERT_Addons/uwauv/uwauvctrer-module.h @@ -220,6 +220,8 @@ class UwAUVCtrErModule : public UwCbrModule { double th_ne; // if x < th_e NO error double accuracy; + vector> rcv_queue; + }; diff --git a/DESERT_Addons/uwauv/uwauverror-b-module.cc b/DESERT_Addons/uwauv/uwauverror-b-module.cc index 0e5ed12a..ee7ce612 100644 --- a/DESERT_Addons/uwauv/uwauverror-b-module.cc +++ b/DESERT_Addons/uwauv/uwauverror-b-module.cc @@ -202,16 +202,14 @@ void UwAUVErrorBModule::initPkt(Packet* p) { std::mt19937 generator(rd()); std::uniform_real_distribution distrib(0.0, 1.0); - double t_e = distrib(generator) ; + 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; - double p_e = std::erfc((((1 - error_p) - m) / std::sqrt(2.0)) / sigma); // 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; // prob of true error (t_e) greater than th_ne if (t_e > (1-error_p)){ if (log_flag == 1) { @@ -221,7 +219,7 @@ void UwAUVErrorBModule::initPkt(Packet* p) { } } - if (p_e > accuracy){ //if p_e is small enough --> no error, otherwise gray zone + if (p_e > accuracy){ //if p_e is small enough --> no error, otherwise error x_e = posit->getX(); y_e = posit->getY(); @@ -274,10 +272,9 @@ void UwAUVErrorBModule::initPkt(Packet* p) { uwAUVh->y() = y_e; uwAUVh->error() = 1; this->p = p; - uwAUVh->sn() = sn; + uwAUVh->sn() = ++sn; } - UwCbrModule::initPkt(p); @@ -335,7 +332,7 @@ void UwAUVErrorBModule::recv(Packet* p) { alarm_mode = true; if (debug_) - std::cout << NOW << " UwAUVErrBModule::recv(Packet *p) for SURE there is an error ("<< x_e <<","<< y_e <<")" + std::cout << NOW << " UwAUVErrBModule::recv(Packet *p) error ("<< x_e <<","<< y_e <<")" "STOP until ctr arrival"<< std::endl; } @@ -346,13 +343,6 @@ void UwAUVErrorBModule::recv(Packet* p) { UwCbrModule::recv(p); - - if(uwAUVh->ack() > 0 && debug_) - std::cout << NOW << " UwAUVErrorBModule::recv(Packet *p) error ACK " - << "received " << uwAUVh->ack()<< std::endl; - else if((uwAUVh->ack())<0 && debug_) - std::cout << NOW << " UwAUVErrorBModule::recv(Packet *p) error NACK " - <<"received"<< std::endl; if (log_flag == 1) { out_file_stats.open("log/position_log_a.csv",std::ios_base::app); diff --git a/DESERT_Addons/uwauv/uwauverror-b-module.h b/DESERT_Addons/uwauv/uwauverror-b-module.h index 73d2955b..1b9f10f6 100644 --- a/DESERT_Addons/uwauv/uwauverror-b-module.h +++ b/DESERT_Addons/uwauv/uwauverror-b-module.h @@ -185,7 +185,6 @@ class UwAUVErrorBModule : public UwCbrModule { UWSMEPosition* posit; /**< AUV position.*/ int last_sn_confirmed;/**< Sequence number of the last command Packete received.*/ int sn; - std::queue buffer; /**< Packets buffer.*/ int drop_old_waypoints; /** < Flag set to 1 to drop waypoints with sequence number lower or equal than last_sn_confirmed.*/ diff --git a/DESERT_Addons/uwauv/uwauverror-module.cc b/DESERT_Addons/uwauv/uwauverror-module.cc index 818ca7fa..8dd56021 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.cc +++ b/DESERT_Addons/uwauv/uwauverror-module.cc @@ -195,15 +195,15 @@ void UwAUVErrorModule::transmit() { } void UwAUVErrorModule::initPkt(Packet* p) { - + hdr_uwcbr *uwcbrh = HDR_UWCBR(p); hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); uwAUVh->error() = 0; - if (alarm_mode != 2 ){ + if (alarm_mode != 2 ){ //if not in alarm mode - if (alarm_mode == 1){ + if (alarm_mode == 1){ //gray zone error_m = getErrorMeasure(t_e); @@ -221,7 +221,8 @@ void UwAUVErrorModule::initPkt(Packet* p) { << "New error, measure: "<< error_m <<", true error: "<< t_e << std::endl; } - if(alarm_mode == 1){ + if(alarm_mode == 1){ // start error timer + if (log_flag == 1) { err_log.open("log/error_log_t.csv",std::ios_base::app); err_log << "G,"<< NOW << "," << posit->getX() <<","<< posit->getY() <<", ON"<< std::endl; @@ -270,7 +271,7 @@ void UwAUVErrorModule::initPkt(Packet* p) { uwAUVh->y() = y_e; uwAUVh->error() = error_m; this->p = p; - uwAUVh->sn() = sn; + uwAUVh->sn() = ++sn; //++ or no? } @@ -315,8 +316,8 @@ void UwAUVErrorModule::recv(Packet* p) { if (uwAUVh->error() < 0 ){ posit->setAlarm(false); - alarm_mode = 0; posit->setdest(posit->getXdest(),posit->getYdest(),posit->getZdest(),speed); + sendTmr_.force_cancel(); sendTmr_.resched(period); @@ -329,17 +330,27 @@ void UwAUVErrorModule::recv(Packet* p) { 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){ - 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(); + 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_) { @@ -372,7 +383,7 @@ void UwAUVErrorModule::recv(Packet* p) { std::cout << NOW << " UwAUVErrModule::recv(Packet *p) for SURE there is an error ("<< x_e <<","<< y_e <<")" "STOP until ctr arrival"<< std::endl; - }else{ + }else{// ->error=0 alarm_mode = 1; @@ -387,9 +398,6 @@ void UwAUVErrorModule::recv(Packet* p) { } UwCbrModule::recv(p); - - - //UwCbrModule::sendPkt(); if (log_flag == 1) { out_file_stats.open("log/position_log_a.csv",std::ios_base::app); @@ -409,23 +417,25 @@ double UwAUVErrorModule::getErrorMeasure(){ // Generate a random value from the uniform distribution t_e = u_dis(gen); - std::normal_distribution<> n_dis(0.0, sigma); // Adjust the standard deviation using the variance + 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; - //double p_e = QFunction(m); - // Calculate the error probability - double p_e = std::erfc(((th_ne - m) / std::sqrt(2.0)) / sigma); // prob of true error (t_e) greater than th_ne - - - //double th_5sig = std::erfc((5*sigma) / std::sqrt(2)) / 2; + double p_e = std::erfc(((th_ne - m) / std::sqrt(2.0)) / sigma)/2; // prob of true error (t_e) greater than th_ne if (p_e > accuracy){ //if p_e is small enough --> no error, otherwise gray zone alarm_mode = 1; + }else{ + if (t_e > th_ne){ + if (log_flag == 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){ @@ -449,8 +459,7 @@ double UwAUVErrorModule::getErrorMeasure(double t_e){ std::random_device rd; std::mt19937 gen(rd()); - std::normal_distribution<> n_dis(0.0, sigma); // Adjust the standard deviation using the variance - + std::normal_distribution<> n_dis(0.0, sigma); // Generate a random value from the Gaussian distribution double noise = n_dis(gen); diff --git a/DESERT_Addons/uwauv/uwauverror-module.h b/DESERT_Addons/uwauv/uwauverror-module.h index d586418d..a7fa262d 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.h +++ b/DESERT_Addons/uwauv/uwauverror-module.h @@ -183,7 +183,6 @@ class UwAUVErrorModule : public UwCbrModule { UWSMEPosition* posit; /**< AUV position.*/ int last_sn_confirmed;/**< Sequence number of the last command Packete received.*/ int sn; - std::queue buffer; /**< Packets buffer.*/ int drop_old_waypoints; /** < Flag set to 1 to drop waypoints with sequence number lower or equal than last_sn_confirmed.*/ @@ -204,7 +203,6 @@ class UwAUVErrorModule : public UwCbrModule { double speed; virtual double getErrorMeasure(); virtual double getErrorMeasure(double t_e); - //virtual double QFunction(double x); double t_e; // True error in that point double sigma; // standard deviation double th_ne; // if x < th_e NO error diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/metric_comp.py b/DESERT_Framework/DESERT/samples/desert_samples/AUV/metric_comp.py index ed8d7666..646da749 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/metric_comp.py +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/metric_comp.py @@ -39,7 +39,7 @@ def plot_auv_coordinates_log(file_path): 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 + else: #4Q -> auv_4 auv_4.append((float(row[1]),float(row[2]))) return auv_1,auv_2,auv_3,auv_4 @@ -116,6 +116,8 @@ def separate_rows(filename): 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) 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 index f5e8e82c..d081975d 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/metric_comp_4.py +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/metric_comp_4.py @@ -108,6 +108,9 @@ def separate_rows(filename): 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) diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_coordinates.py b/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_coordinates.py index 5dbf2d72..7713d07c 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_coordinates.py +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_coordinates.py @@ -131,13 +131,14 @@ def plot_movement_log(file_path,t,axis): 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(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') @@ -146,6 +147,6 @@ def plot_movement_log(file_path,t,axis): ax.set_ylabel('Y') ax.legend() #ax.set_zlabel('Z') -plt.show() -#tikzplotlib.save('traj.tex') -#plt.close() \ No newline at end of file +#plt.show() +tikzplotlib.save('traj.tex') +plt.close() \ No newline at end of file diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/result_compute.py b/DESERT_Framework/DESERT/samples/desert_samples/AUV/result_compute.py index a960f89b..9b142c2b 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/result_compute.py +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/result_compute.py @@ -7,9 +7,6 @@ def compute_power(): v = 1.5 - Cd = 11.3 - A = 0.0048 - a_dens = 1025 Pm= 16.3*(v**2) #Pd = 0.5*a_dens*(v**3)*Cd*A #1/2*rho*v^3*C*A return Pm#+Pd @@ -63,15 +60,15 @@ def compute_error(file_path,pkt_size): 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]): - m_tp[float(row[0])]=[float(row[6])] + 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]): + 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]) @@ -90,10 +87,10 @@ def compute_error(file_path,pkt_size): #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*0.01/1000] + 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] + #auv_e[float(row[0])] = [sent_u_er else: @@ -118,6 +115,7 @@ def compute_error(file_path,pkt_size): 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]) @@ -136,57 +134,59 @@ def compute_error(file_path,pkt_size): #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*0.01/1000) + 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] + #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: - m_tp[float(row[0])].append(float(row[6])) 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])+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]))] + 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]): + 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 + 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 = compute_error(file_path,125) +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 = compute_error(file_path,5) +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()} @@ -207,13 +207,12 @@ def compute_error(file_path,pkt_size): pr2.columns= ['Key','Values'] sns.lineplot(data=pr2,x='Key',y='Values',marker='^',markersize='8',label='SER') -plt.title('Precision') -plt.ylim(bottom=0,top=1) +plt.ylim(bottom=0) plt.xscale('log') plt.grid(True, linestyle='dashed', linewidth=0.5, color='gray',axis='y',which='both') -plt.xlabel('$\epsilon$') -plt.show() -#tikzplotlib.save('pr.tex') +plt.xlabel('$\\theta$') +#plt.show() +tikzplotlib.save('pr.tex') plt.close() @@ -237,12 +236,11 @@ def compute_error(file_path,pkt_size): sns.lineplot(data=rc2,x='Key',y='Values',marker='^',markersize='8',label='SER') plt.ylim(bottom=0) -plt.title('Recall') plt.xscale('log') plt.grid(True, linestyle='dashed', linewidth=0.5, color='gray',axis='y',which='both') -plt.xlabel('$\epsilon$') -plt.show() -#tikzplotlib.save('rec.tex') +plt.xlabel('$\\theta$') +#plt.show() +tikzplotlib.save('rec.tex') plt.close() @@ -268,12 +266,12 @@ def compute_error(file_path,pkt_size): plt.xscale('log') #plt.yscale('log') plt.grid(True, linestyle='dashed', linewidth=0.5, color='gray',axis='y',which='both') -plt.xlabel('$\epsilon$') +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.tex') +#plt.title('ASV\'s Energy Consumption (movement) per Error') +#plt.show() +tikzplotlib.save('energy_mov.tex') plt.close() ax = plt.figure() @@ -298,46 +296,47 @@ def compute_error(file_path,pkt_size): plt.xscale('log') #plt.yscale('log') plt.grid(True, linestyle='dashed', linewidth=0.5, color='gray',axis='y',which='both') -plt.xlabel('$\epsilon$') +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.tex') +#plt.title('ASV\'s Energy Consumption (total)') +#plt.show() +tikzplotlib.save('energy_tx.tex') plt.close() -ax = plt.figure() +#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') +#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.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.tex') -plt.close() +#plt.title('AUV\'s Energy Consumption (tx)') +#plt.show() +#tikzplotlib.save('energy_tx.tex') +#plt.close() ax = plt.figure() @@ -361,13 +360,15 @@ def compute_error(file_path,pkt_size): plt.xscale('log') #plt.yscale('log') plt.grid(True, linestyle='dashed', linewidth=0.5, color='gray',axis='y',which='both') -plt.xlabel('$\epsilon$') +plt.xlabel('$\\theta$') plt.ylabel('Time') -plt.title('Average Downtime per Error') -plt.show() -#tikzplotlib.save('time.tex') +#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) @@ -388,11 +389,40 @@ def compute_error(file_path,pkt_size): plt.xscale('log') plt.yscale('log') plt.grid(True, linestyle='dashed', linewidth=0.5, color='gray',axis='y',which='both') -plt.xlabel('$\epsilon$') +plt.xlabel('$\\theta$') plt.ylabel('Distance') -plt.title('AUV\'s Distance Covered') +#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() + From f4fc526f71d708746905587ec3e80f539f6c7933 Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Wed, 13 Sep 2023 16:49:22 +0200 Subject: [PATCH 23/36] review correction p1 --- DESERT_Addons/uwauv/Makefile.am | 2 +- DESERT_Addons/uwauv/initlib.cc | 2 +- DESERT_Addons/uwauv/m4/desert.m4 | 6 +- DESERT_Addons/uwauv/uwauv-init.tcl | 2 +- DESERT_Addons/uwauv/uwauv-module.cc | 53 +++--- DESERT_Addons/uwauv/uwauv-module.h | 51 ++--- DESERT_Addons/uwauv/uwauv-packet.h | 2 +- DESERT_Addons/uwauv/uwauvctr-module.cc | 39 ++-- DESERT_Addons/uwauv/uwauvctr-module.h | 34 ++-- DESERT_Addons/uwauv/uwauvctrer-b-module.cc | 33 ++-- DESERT_Addons/uwauv/uwauvctrer-b-module.h | 35 ++-- DESERT_Addons/uwauv/uwauvctrer-module.cc | 53 ++---- DESERT_Addons/uwauv/uwauvctrer-module.h | 32 ++-- DESERT_Addons/uwauv/uwauverror-b-module.cc | 49 ++--- DESERT_Addons/uwauv/uwauverror-b-module.h | 55 +++--- DESERT_Addons/uwauv/uwauverror-module.cc | 51 ++--- DESERT_Addons/uwauv/uwauverror-module.h | 25 +-- DESERT_Framework/DESERT/Makefile.am | 2 +- DESERT_Framework/DESERT/configure.ac | 4 +- .../Makefile.am | 20 +- .../initlib.cpp | 18 +- .../uwsmwpposition-default.tcl} | 6 +- .../uwsmwpposition.cpp} | 179 ++++-------------- .../uwsmwpposition.h} | 105 ++++++---- .../desert_samples/AUV/test_uwauv_error.tcl | 13 +- .../AUV/test_uwauv_error_basic.tcl | 15 +- 26 files changed, 369 insertions(+), 517 deletions(-) rename DESERT_Framework/DESERT/mobility/{uwsmeposition => uwsmwpposition}/Makefile.am (76%) rename DESERT_Framework/DESERT/mobility/{uwsmeposition => uwsmwpposition}/initlib.cpp (83%) rename DESERT_Framework/DESERT/mobility/{uwsmeposition/uwsmeposition-default.tcl => uwsmwpposition/uwsmwpposition-default.tcl} (94%) rename DESERT_Framework/DESERT/mobility/{uwsmeposition/uwsmeposition.cpp => uwsmwpposition/uwsmwpposition.cpp} (69%) rename DESERT_Framework/DESERT/mobility/{uwsmeposition/uwsmeposition.h => uwsmwpposition/uwsmwpposition.h} (54%) diff --git a/DESERT_Addons/uwauv/Makefile.am b/DESERT_Addons/uwauv/Makefile.am index 16c03384..cc7c5082 100644 --- a/DESERT_Addons/uwauv/Makefile.am +++ b/DESERT_Addons/uwauv/Makefile.am @@ -31,7 +31,7 @@ AM_CXXFLAGS = -Wall -ggdb3 lib_LTLIBRARIES = libuwauv.la -libuwauv_la_SOURCES = uwauv-module.cc uwauv-module.h uwauverror-module.cc uwauverror-module.h uwauverror-b-module.cc uwauverror-b-module.h uwauv-packet.h uwauvctr-module.cc uwauvctr-module.h uwauvctrer-module.cc uwauvctrer-module.h uwauvctrer-b-module.cc uwauvctrer-b-module.h initlib.cc +libuwauv_la_SOURCES = uwauv-module.cc uwauverror-module.cc uwauverror-b-module.cc uwauvctr-module.cc uwauvctrer-module.cc uwauvctrer-b-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@ diff --git a/DESERT_Addons/uwauv/initlib.cc b/DESERT_Addons/uwauv/initlib.cc index 66d40aaa..c137a3b4 100644 --- a/DESERT_Addons/uwauv/initlib.cc +++ b/DESERT_Addons/uwauv/initlib.cc @@ -28,7 +28,7 @@ /** * @file initlib.cc - * @author Filippo Campagnaro, Alessia Ortile + * @author Alessia Ortile * @version 1.0.0 * * \brief Provides the initialization of uwauv libraries. diff --git a/DESERT_Addons/uwauv/m4/desert.m4 b/DESERT_Addons/uwauv/m4/desert.m4 index fcd5a26e..97c6b179 100644 --- a/DESERT_Addons/uwauv/m4/desert.m4 +++ b/DESERT_Addons/uwauv/m4/desert.m4 @@ -52,7 +52,7 @@ AC_DEFUN([AC_ARG_WITH_DESERT],[ network/uwip \ transport/uwudp \ mobility/uwsmposition \ - mobility/uwsmeposition + mobility/uwsmwpposition do echo "considering dir \"$dir\"" DESERT_CPPFLAGS="$DESERT_CPPFLAGS -I${DESERT_PATH}/${dir}" @@ -64,7 +64,7 @@ AC_DEFUN([AC_ARG_WITH_DESERT],[ uwip \ uwudp \ uwsmposition \ - uwsmeposition + uwsmwpposition do DESERT_LIBADD="$DESERT_LIBADD -l${lib}" done @@ -104,7 +104,7 @@ AC_DEFUN([AC_ARG_WITH_DESERT_BUILD],[ network/uwip \ transport/uwudp \ mobility/uwsmposition \ - mobility/uwsmeposition + mobility/uwsmwpposition do echo "considering dir \"$dir\"" DESERT_LDFLAGS_BUILD="$DESERT_LDFLAGS_BUILD -L${DESERT_PATH_BUILD}/${dir}" diff --git a/DESERT_Addons/uwauv/uwauv-init.tcl b/DESERT_Addons/uwauv/uwauv-init.tcl index 76bf500e..f9c01c4e 100644 --- a/DESERT_Addons/uwauv/uwauv-init.tcl +++ b/DESERT_Addons/uwauv/uwauv-init.tcl @@ -125,6 +125,6 @@ Module/UW/AUV/ERB instproc init {args} { Position/UWSM set debug_ 0 -Position/UWSME 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 index 256623c3..39b066e9 100644 --- a/DESERT_Addons/uwauv/uwauv-module.cc +++ b/DESERT_Addons/uwauv/uwauv-module.cc @@ -28,7 +28,7 @@ /** * @file uwauv-module.cc -* @author Filippo Campagnaro, Alessia Ortile +* @author Alessia Ortile * @version 1.0.0 * * \brief Provides the UWAUV class implementation. @@ -92,9 +92,9 @@ UwAUVModule::UwAUVModule() , log_flag(0) , out_file_stats(0) { - UWSMEPosition p = UWSMEPosition(); + UWSMWPPosition p = UWSMWPPosition(); posit=&p; - bind("ackTimeout_", (int*) &ackTimeout); + bind("ackTimeout_", (double*) &ackTimeout); bind("ackPriority_", (int*) &ackPriority); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); bind("log_flag_", (int*) &log_flag ); @@ -106,7 +106,7 @@ UwAUVModule::UwAUVModule() } -UwAUVModule::UwAUVModule(UWSMEPosition* p) +UwAUVModule::UwAUVModule(UWSMWPPosition* p) : UwCbrModule() , last_sn_confirmed(0) , ack(0) @@ -120,7 +120,7 @@ UwAUVModule::UwAUVModule(UWSMEPosition* p) , out_file_stats(0) { posit = p; - bind("ackTimeout_", (int*) &ackTimeout); + bind("ackTimeout_", (double*) &ackTimeout); bind("ackPriority_", (int*) &ackPriority); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); bind("log_flag_", (int*) &log_flag ); @@ -135,7 +135,7 @@ UwAUVModule::UwAUVModule(UWSMEPosition* p) UwAUVModule::~UwAUVModule() {} -void UwAUVModule::setPosition(UWSMEPosition* p){ +void UwAUVModule::setPosition(UWSMWPPosition* p){ posit = p; } @@ -169,10 +169,18 @@ int UwAUVModule::command(int argc, const char*const* argv) { } else if(argc == 3){ if (strcasecmp(argv[1], "setPosition") == 0) { - UWSMEPosition* p = dynamic_cast (tcl.lookup(argv[2])); - posit=p; - tcl.resultf("%s", "position Setted\n"); - return TCL_OK; + + 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) { @@ -186,6 +194,9 @@ int UwAUVModule::command(int argc, const char*const* argv) { if (atof(argv[2]) == 3) { ackPolicy = ACK_PGBK_OR_TO; return TCL_OK; + }else{ + cerr<<"Plicy not supported" << std::endl; + return TCL_ERROR; } } if (strcasecmp(argv[1], "setAckTimeout") == 0) { @@ -198,20 +209,20 @@ int UwAUVModule::command(int argc, const char*const* argv) { } } else if(argc == 5){ - if (strcasecmp(argv[1], "setdest") == 0) { - posit->setdest(atof(argv[2]),atof(argv[3]),atof(argv[4])); + 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])); + }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])); + 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])); + } else if (strcasecmp(argv[1], "addDest") == 0) { + posit->addDest(atof(argv[2]),atof(argv[3]),atof(argv[4]),atof(argv[5])); return TCL_OK; } } @@ -245,10 +256,6 @@ void UwAUVModule::initPkt(Packet* p) { priority_ = 0; } -void UwAUVModule::recv(Packet* p, Handler* h) { - recv(p); -} - void UwAUVModule::recv(Packet* p) { hdr_uwAUV_ctr* uwAUVh = HDR_UWAUV_CTR(p); @@ -262,7 +269,7 @@ void UwAUVModule::recv(Packet* p) { } else { //packet in order - posit->adddest(uwAUVh->x(),uwAUVh->y(),uwAUVh->z(),uwAUVh->speed()); + posit->addDest(uwAUVh->x(),uwAUVh->y(),uwAUVh->z(),uwAUVh->speed()); last_sn_confirmed = uwAUVh->sn(); } diff --git a/DESERT_Addons/uwauv/uwauv-module.h b/DESERT_Addons/uwauv/uwauv-module.h index 5f36457d..838ac780 100644 --- a/DESERT_Addons/uwauv/uwauv-module.h +++ b/DESERT_Addons/uwauv/uwauv-module.h @@ -28,7 +28,7 @@ /** * @file uwauv-module.h -* @author Filippo Campagnaro Alessia Ortile +* @author Alessia Ortile * @version 1.0.0 * * \brief Provides the definition of the class UWAUV. @@ -45,7 +45,7 @@ #define UWAUV_MODULE_H #include #include -#include "uwsmeposition.h" +#include "uwsmwpposition.h" #include #include #define UWAUV_DROP_REASON_UNKNOWN_TYPE "UKT" /**< Reason for a drop in a UWAUV module. */ @@ -87,9 +87,9 @@ class UwAUVModule : public UwCbrModule { /** * Constructor with position setting of UwAUVModule class. * - * @param UWSMEPosition* p Pointer to the AUV position + * @param UWSMWPPosition* p Pointer to the AUV position */ - UwAUVModule(UWSMEPosition* p); + UwAUVModule(UWSMWPPosition* p); /** * Destructor of UwAUVModule class. @@ -97,50 +97,42 @@ class UwAUVModule : public UwCbrModule { 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. - * - **/ + * 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. - */ + * 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*); - /** - * Performs the reception of packets from upper and lower layers. - * - * @param Packet* Pointer to the packet will be received. - * @param Handler* Handler. - */ - virtual void recv(Packet* p, Handler* h); - /** * Sets the position of the AUV * - * @param UWSMEPosition * p Pointer to the AUV position + * @param UWSMWPPosition * p Pointer to the AUV position */ - virtual void setPosition(UWSMEPosition* p); + virtual void setPosition(UWSMWPPosition* p); /** * Returns the position of the AUV * * @return the current AUV position */ - inline UWSMEPosition* getPosition() { return posit; } + inline UWSMWPPosition* getPosition() const { return posit; } /** * Returns the size in byte of a hdr_uwAUV_monitoring packet header. @@ -166,7 +158,7 @@ class UwAUVModule : public UwCbrModule { enum UWAUV_ACK_POLICY { ACK_PIGGYBACK, ACK_IMMEDIATELY, ACK_PGBK_OR_TO }; - UWSMEPosition* posit; /**< AUV position.*/ + 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.*/ @@ -177,7 +169,7 @@ class UwAUVModule : public UwCbrModule { 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.*/ - int ackTimeout; /**< Timeout after which ACK is sent if ackPolicy = ACK_PGBK_OR_TO. */ + double ackTimeout; /**< Timeout after which ACK is sent if ackPolicy = ACK_PGBK_OR_TO. */ UwAUVSendAckTimer ackTimer_; /**UWAUV monitoring and control packets header description. diff --git a/DESERT_Addons/uwauv/uwauvctr-module.cc b/DESERT_Addons/uwauv/uwauvctr-module.cc index 6699aa1c..af0e0e68 100644 --- a/DESERT_Addons/uwauv/uwauvctr-module.cc +++ b/DESERT_Addons/uwauv/uwauvctr-module.cc @@ -28,7 +28,7 @@ /** * @file uwauvctr-module.cc -* @author Filippo Campagnaro, Alessia Ortile +* @author Alessia Ortile * @version 1.0.0 * * \brief Provides the UWAUVCtr class implementation. @@ -69,7 +69,7 @@ static class UwAUVCtrModuleClass : public TclClass { } } class_module_uwAUV_ctr; -UwAUVCtrModule::UwAUVCtrModule(UWSMEPosition* p) +UwAUVCtrModule::UwAUVCtrModule(UWSMWPPosition* p) : UwCbrModule() , sn(0) , adaptiveRTO(0) @@ -78,9 +78,8 @@ UwAUVCtrModule::UwAUVCtrModule(UWSMEPosition* p) posit=p; speed=0.5; bind("adaptiveRTO_", (int *) &adaptiveRTO); - if (adaptiveRTO == 1) { - bind("adaptiveRTO_parameter_", (double *) &adaptiveRTO_parameter); - } + 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; @@ -94,15 +93,12 @@ UwAUVCtrModule::UwAUVCtrModule() , adaptiveRTO(0) , adaptiveRTO_parameter(0.5) { - p = NULL; - UWSMEPosition p = UWSMEPosition(); - posit=&p; - //posit = Position(); + + posit= new UWSMWPPosition(); speed = 0.5; bind("adaptiveRTO_", (int *) &adaptiveRTO); - if (adaptiveRTO == 1) { - bind("adaptiveRTO_parameter_", (double *) &adaptiveRTO_parameter); - } + 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; @@ -140,9 +136,16 @@ int UwAUVCtrModule::command(int argc, const char*const* argv) { } else if(argc == 3){ if (strcasecmp(argv[1], "setPosition") == 0) { - UWSMEPosition* p = dynamic_cast (tcl.lookup(argv[2])); - posit = p; - return TCL_OK; + 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; @@ -192,7 +195,7 @@ void UwAUVCtrModule::transmit() { void UwAUVCtrModule::start() {} -void UwAUVCtrModule::setPosition(UWSMEPosition* p){ +void UwAUVCtrModule::setPosition(UWSMWPPosition* p){ posit = p; } @@ -235,10 +238,6 @@ void UwAUVCtrModule::initPkt(Packet* p) { } } -void UwAUVCtrModule::recv(Packet* p, Handler* h) { - recv(p); -} - void UwAUVCtrModule::recv(Packet* p) { hdr_uwAUV_monitoring* monitoring = HDR_UWAUV_MONITORING(p); diff --git a/DESERT_Addons/uwauv/uwauvctr-module.h b/DESERT_Addons/uwauv/uwauvctr-module.h index 58e88af9..6fd28f63 100644 --- a/DESERT_Addons/uwauv/uwauvctr-module.h +++ b/DESERT_Addons/uwauv/uwauvctr-module.h @@ -28,7 +28,7 @@ // /** * @file uwauvctr-module.h -* @author Filippo Campagnaro +* @author Alessia Ortile * @version 1.0.0 * * \brief Provides the definition of the class UWAUV. @@ -47,7 +47,7 @@ #define UWAUV_CTR_MODULE_H #include #include "uwauv-packet.h" -#include "uwsmeposition.h" +#include #include "node-core.h" #include #define UWAUV_DROP_REASON_UNKNOWN_TYPE "UKT" /**< Reason for a drop in a UWAUV module. */ @@ -65,9 +65,9 @@ class UwAUVCtrSendTimer : public UwSendTimer { public: /** - * Conscructor of UwSendTimer class - * @param UwAUVCtrModule *m pointer to an object of type UwAUVCtrModule - */ + * Conscructor of UwSendTimer class + * @param UwAUVCtrModule *m pointer to an object of type UwAUVCtrModule + */ UwAUVCtrSendTimer(UwAUVCtrModule *m) : UwSendTimer((UwCbrModule*)(m)){ }; }; @@ -86,7 +86,7 @@ class UwAUVCtrModule : public UwCbrModule { /** * Constructor of UwAUVCtrModule class with position setting. */ - UwAUVCtrModule(UWSMEPosition* p); + UwAUVCtrModule(UWSMWPPosition* p); /** * Destructor of UwAUVCtrModule class. @@ -104,10 +104,10 @@ class UwAUVCtrModule : public UwCbrModule { 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. - */ + * 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) ; /** @@ -120,14 +120,14 @@ class UwAUVCtrModule : public UwCbrModule { * * @param Position * p Pointer to the AUVCtr position */ - virtual void setPosition(UWSMEPosition* p); + virtual void setPosition(UWSMWPPosition* p); /** * Returns the position of the AUVCtr * * @return the current AUVCtr position */ - inline UWSMEPosition* getPosition() { return posit;} + inline UWSMWPPosition* getPosition() const { return posit;} /** * Returns the last AUV position monitored @@ -149,14 +149,6 @@ class UwAUVCtrModule : public UwCbrModule { */ virtual void recv(Packet*); - /** - * Performs the reception of packets from upper and lower layers. - * - * @param Packet* Pointer to the packet will be received. - * @param Handler* Handler. - */ - virtual void recv(Packet* p, Handler* h); - /** * Creates and transmits a packet. * @@ -187,7 +179,7 @@ class UwAUVCtrModule : public UwCbrModule { protected: - UWSMEPosition* posit; /**< Controller position.*/ + 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.*/ diff --git a/DESERT_Addons/uwauv/uwauvctrer-b-module.cc b/DESERT_Addons/uwauv/uwauvctrer-b-module.cc index 1535c294..3dd7562d 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-b-module.cc +++ b/DESERT_Addons/uwauv/uwauvctrer-b-module.cc @@ -28,7 +28,7 @@ /** * @file uwauvctrer-b-module.cc -* @author Filippo Campagnaro, Alessia Ortile +* @author Alessia Ortile * @version 1.0.0 * * \brief Provides the UWAUVCtrEr class implementation. @@ -70,7 +70,7 @@ static class UwAUVCtrErBModuleClass : public TclClass { } class_module_uwAUV_error; -UwAUVCtrErBModule::UwAUVCtrErBModule(UWSMEPosition* p) +UwAUVCtrErBModule::UwAUVCtrErBModule(UWSMWPPosition* p) : UwCbrModule() , last_sn_confirmed(0) , sn(0) @@ -98,9 +98,7 @@ UwAUVCtrErBModule::UwAUVCtrErBModule() , speed(1.5) { - p = NULL; - UWSMEPosition p = UWSMEPosition(); - posit=&p; + posit= new UWSMWPPosition(); x_sorg = posit->getX(); y_sorg = posit->getY(); @@ -141,9 +139,15 @@ int UwAUVCtrErBModule::command(int argc, const char*const* argv) { } else if(argc == 3){ if (strcasecmp(argv[1], "setPosition") == 0) { - UWSMEPosition* p = dynamic_cast (tcl.lookup(argv[2])); - posit = p; - return TCL_OK; + 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]); @@ -154,7 +158,7 @@ int UwAUVCtrErBModule::command(int argc, const char*const* argv) { return UwCbrModule::command(argc,argv); } -void UwAUVCtrErBModule::setPosition(UWSMEPosition* p){ +void UwAUVCtrErBModule::setPosition(UWSMWPPosition* p){ posit = p; x_sorg = posit->getX(); @@ -242,7 +246,7 @@ void UwAUVCtrErBModule::initPkt(Packet* p) { x_err = alarm_queue[0][0]; y_err = alarm_queue[0][1]; - posit->setdest(x_err,y_err,posit->getZ(),speed); + posit->setDest(x_err,y_err,posit->getZ(),speed); alarm_mode = true; alarm_queue.erase(alarm_queue.begin()); @@ -286,10 +290,6 @@ void UwAUVCtrErBModule::initPkt(Packet* p) { UwCbrModule::initPkt(p); } -void UwAUVCtrErBModule::recv(Packet* p, Handler* h) { - recv(p); -} - void UwAUVCtrErBModule::recv(Packet* p) { hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); @@ -321,7 +321,7 @@ void UwAUVCtrErBModule::recv(Packet* p) { x_sorg = posit->getX(); y_sorg = posit->getY(); - posit->setdest(x_err,y_err,posit->getZ(),speed); + posit->setDest(x_err,y_err,posit->getZ(),speed); alarm_mode = true; @@ -342,7 +342,7 @@ void UwAUVCtrErBModule::recv(Packet* p) { x_err = alarm_queue[0][0]; y_err = alarm_queue[0][1]; - posit->setdest(x_err,y_err,posit->getZ(),speed); + posit->setDest(x_err,y_err,posit->getZ(),speed); alarm_mode = true; @@ -408,7 +408,6 @@ void UwAUVCtrErBModule::recv(Packet* p) { } UwCbrModule::recv(p); - //transmit(); } diff --git a/DESERT_Addons/uwauv/uwauvctrer-b-module.h b/DESERT_Addons/uwauv/uwauvctrer-b-module.h index d21db0cd..21de9121 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-b-module.h +++ b/DESERT_Addons/uwauv/uwauvctrer-b-module.h @@ -27,8 +27,8 @@ // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // /** -* @file uwauvctr-module.h -* @author Filippo Campagnaro, Alessia Ortile +* @file uwauvctrer-b-module.h +* @author Alessia Ortile * @version 1.0.0 * * \brief Provides the definition of the class UWAUV. @@ -47,7 +47,7 @@ #define UWAUVError_MODULE_H #include #include "uwauv-packet.h" -#include "uwsmeposition.h" +#include "uwsmwpposition.h" #include "node-core.h" #include #include @@ -89,7 +89,7 @@ class UwAUVCtrErBModule : public UwCbrModule { /** * Constructor of UwAUVCtrModule class with position setting. */ - UwAUVCtrErBModule(UWSMEPosition* p); + UwAUVCtrErBModule(UWSMWPPosition* p); /** * Destructor of UwAUVCtrModule class. @@ -107,10 +107,10 @@ class UwAUVCtrErBModule : public UwCbrModule { 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. - */ + * 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) ; /** @@ -118,14 +118,14 @@ class UwAUVCtrErBModule : public UwCbrModule { * * @param Position * p Pointer to the AUVCtr position */ - virtual void setPosition(UWSMEPosition* p); + virtual void setPosition(UWSMWPPosition* p); /** * Returns the position of the AUVCtr * * @return the current AUVCtr position */ - inline UWSMEPosition* getPosition() { return posit;} + inline UWSMWPPosition* getPosition() const { return posit;} /** * Reset retransmissions @@ -148,19 +148,6 @@ class UwAUVCtrErBModule : public UwCbrModule { */ virtual void recv(Packet*); - /** - * Performs the reception of packets from upper and lower layers. - * - * @param Packet* Pointer to the packet will be received. - * @param Handler* Handler. - */ - virtual void recv(Packet* p, Handler* h); - - /** - * Start the controller. - */ - //virtual void start(); - /** * Returns the size in byte of a hdr_uwAUV_monitoring packet header. * @@ -188,7 +175,7 @@ class UwAUVCtrErBModule : public UwCbrModule { protected: - UWSMEPosition* posit; /**< Controller position.*/ + 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; diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.cc b/DESERT_Addons/uwauv/uwauvctrer-module.cc index b5562c6d..b1337f5d 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.cc +++ b/DESERT_Addons/uwauv/uwauvctrer-module.cc @@ -28,7 +28,7 @@ /** * @file uwauvctrer-module.cc -* @author Filippo Campagnaro, Alessia Ortile +* @author Alessia Ortile * @version 1.0.0 * * \brief Provides the UWAUVCtrEr class implementation. @@ -70,7 +70,7 @@ static class UwAUVCtrErModuleClass : public TclClass { } class_module_uwAUV_error; -UwAUVCtrErModule::UwAUVCtrErModule(UWSMEPosition* p) +UwAUVCtrErModule::UwAUVCtrErModule(UWSMWPPosition* p) : UwCbrModule() , last_sn_confirmed(0) , sn(0) @@ -104,9 +104,7 @@ UwAUVCtrErModule::UwAUVCtrErModule() , accuracy(0.001) { - p = NULL; - UWSMEPosition p = UWSMEPosition(); - posit=&p; + posit = new UWSMWPPosition(); x_sorg = posit->getX(); y_sorg = posit->getY(); @@ -150,9 +148,15 @@ int UwAUVCtrErModule::command(int argc, const char*const* argv) { } else if(argc == 3){ if (strcasecmp(argv[1], "setPosition") == 0) { - UWSMEPosition* p = dynamic_cast (tcl.lookup(argv[2])); - posit = p; - return TCL_OK; + 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]); @@ -164,7 +168,7 @@ int UwAUVCtrErModule::command(int argc, const char*const* argv) { } -void UwAUVCtrErModule::setPosition(UWSMEPosition* p){ +void UwAUVCtrErModule::setPosition(UWSMWPPosition* p){ posit = p; x_sorg = posit->getX(); @@ -275,30 +279,10 @@ void UwAUVCtrErModule::initPkt(Packet* p) { << 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->setdest(x_err,y_err,posit->getZ(),speed); - alarm_mode = 2; - - 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; - } - - }*/ - }else{ uwAUVh->error() = 1; - uwAUVh->sn() = ++sn; //++ or no? + uwAUVh->sn() = ++sn; uwAUVh->x() = x_err; uwAUVh->y() = y_err; this->p = p; @@ -315,10 +299,6 @@ void UwAUVCtrErModule::initPkt(Packet* p) { } -void UwAUVCtrErModule::recv(Packet* p, Handler* h) { - recv(p); -} - void UwAUVCtrErModule::recv(Packet* p) { hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); @@ -404,7 +384,7 @@ void UwAUVCtrErModule::recv(Packet* p) { x_sorg = posit->getX(); y_sorg = posit->getY(); - posit->setdest(x_err,y_err,posit->getZ(),speed); + posit->setDest(x_err,y_err,posit->getZ(),speed); alarm_mode = 2; if (debug_) @@ -437,7 +417,7 @@ void UwAUVCtrErModule::recv(Packet* p) { x_err = alarm_queue[0][0]; y_err = alarm_queue[0][1]; - posit->setdest(x_err,y_err,posit->getZ(),speed); + posit->setDest(x_err,y_err,posit->getZ(),speed); alarm_mode = 2; x_sorg = posit->getX(); @@ -544,7 +524,6 @@ void UwAUVCtrErModule::recv(Packet* p) { } UwCbrModule::recv(p); - //transmit(); } int UwAUVCtrErModule::checkError(double m, int n_pkt, float x, float y){ diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.h b/DESERT_Addons/uwauv/uwauvctrer-module.h index 6e3d267c..9ba594ce 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.h +++ b/DESERT_Addons/uwauv/uwauvctrer-module.h @@ -27,8 +27,8 @@ // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // /** -* @file uwauvctr-module.h -* @author Filippo Campagnaro, Alessia Ortile +* @file uwauvctrer-module.h +* @author Alessia Ortile * @version 1.0.0 * * \brief Provides the definition of the class UWAUV. @@ -47,7 +47,7 @@ #define UWAUVError_MODULE_H #include #include "uwauv-packet.h" -#include "uwsmeposition.h" +#include "uwsmwpposition.h" #include "node-core.h" #include #include @@ -89,7 +89,7 @@ class UwAUVCtrErModule : public UwCbrModule { /** * Constructor of UwAUVCtrModule class with position setting. */ - UwAUVCtrErModule(UWSMEPosition* p); + UwAUVCtrErModule(UWSMWPPosition* p); /** * Destructor of UwAUVCtrModule class. @@ -107,10 +107,10 @@ class UwAUVCtrErModule : public UwCbrModule { 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. - */ + * 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) ; /** @@ -123,14 +123,14 @@ class UwAUVCtrErModule : public UwCbrModule { * * @param Position * p Pointer to the AUVCtr position */ - virtual void setPosition(UWSMEPosition* p); + virtual void setPosition(UWSMWPPosition* p); /** * Returns the position of the AUVCtr * * @return the current AUVCtr position */ - inline UWSMEPosition* getPosition() { return posit;} + inline UWSMWPPosition* getPosition() const { return posit;} /** * Creates and transmits a packet. @@ -147,14 +147,6 @@ class UwAUVCtrErModule : public UwCbrModule { */ virtual void recv(Packet*); - /** - * Performs the reception of packets from upper and lower layers. - * - * @param Packet* Pointer to the packet will be received. - * @param Handler* Handler. - */ - virtual void recv(Packet* p, Handler* h); - /** * Returns the size in byte of a hdr_uwAUV_monitoring packet header. * @@ -178,11 +170,9 @@ class UwAUVCtrErModule : public UwCbrModule { float getDistance(float x_s,float y_s, float x_d, float y_d); - - protected: - UWSMEPosition* posit; /**< Controller position.*/ + 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; diff --git a/DESERT_Addons/uwauv/uwauverror-b-module.cc b/DESERT_Addons/uwauv/uwauverror-b-module.cc index ee7ce612..b6e5288e 100644 --- a/DESERT_Addons/uwauv/uwauverror-b-module.cc +++ b/DESERT_Addons/uwauv/uwauverror-b-module.cc @@ -27,8 +27,8 @@ // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /** -* @file uwauv-module.cc -* @author Filippo Campagnaro, Alessia Ortile +* @file uwauverror-b-module.cc +* @author Alessia Ortile * @version 1.0.0 * * \brief Provides the UWAUVError class implementation. @@ -81,8 +81,7 @@ UwAUVErrorBModule::UwAUVErrorBModule() , speed(0.5) , accuracy(0.01) { - UWSMEPosition p = UWSMEPosition(); - posit=&p; + posit= new UWSMWPPosition(); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); bind("log_flag_", (int*) &log_flag ); bind("period_", (int*) &period ); @@ -92,7 +91,7 @@ UwAUVErrorBModule::UwAUVErrorBModule() } -UwAUVErrorBModule::UwAUVErrorBModule(UWSMEPosition* p) +UwAUVErrorBModule::UwAUVErrorBModule(UWSMWPPosition* p) : UwCbrModule() , last_sn_confirmed(0) , sn(0) @@ -116,7 +115,7 @@ UwAUVErrorBModule::UwAUVErrorBModule(UWSMEPosition* p) UwAUVErrorBModule::~UwAUVErrorBModule() {} -void UwAUVErrorBModule::setPosition(UWSMEPosition* p){ +void UwAUVErrorBModule::setPosition(UWSMWPPosition* p){ posit = p; } @@ -149,27 +148,33 @@ int UwAUVErrorBModule::command(int argc, const char*const* argv) { } else if(argc == 3){ if (strcasecmp(argv[1], "setPosition") == 0) { - UWSMEPosition* p = dynamic_cast (tcl.lookup(argv[2])); - posit=p; - tcl.resultf("%s", "position Setted\n"); - return TCL_OK; + 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])); + 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])); + }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])); + 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])); + }else if (strcasecmp(argv[1], "addDest") == 0) { + posit->addDest(atof(argv[2]),atof(argv[3]),atof(argv[4]),atof(argv[5])); return TCL_OK; } @@ -224,7 +229,7 @@ void UwAUVErrorBModule::initPkt(Packet* p) { x_e = posit->getX(); y_e = posit->getY(); - posit->setdest(posit->getXdest(),posit->getYdest(),posit->getZdest(),0); + posit->setDest(posit->getXdest(),posit->getYdest(),posit->getZdest(),0); posit->setAlarm(true); alarm_mode = true; @@ -287,10 +292,6 @@ void UwAUVErrorBModule::initPkt(Packet* p) { } -void UwAUVErrorBModule::recv(Packet* p, Handler* h) { - recv(p); -} - void UwAUVErrorBModule::recv(Packet* p) { hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); @@ -310,7 +311,7 @@ void UwAUVErrorBModule::recv(Packet* p) { posit->setAlarm(false); alarm_mode = 0; - posit->setdest(posit->getXdest(),posit->getYdest(),posit->getZdest(),speed); + posit->setDest(posit->getXdest(),posit->getYdest(),posit->getZdest(),speed); //wait an entire period before sending a new img sendTmr_.force_cancel(); diff --git a/DESERT_Addons/uwauv/uwauverror-b-module.h b/DESERT_Addons/uwauv/uwauverror-b-module.h index 1b9f10f6..a8a3025a 100644 --- a/DESERT_Addons/uwauv/uwauverror-b-module.h +++ b/DESERT_Addons/uwauv/uwauverror-b-module.h @@ -27,8 +27,8 @@ // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /** -* @file uwauv-module.h -* @author Filippo Campagnaro Alessia Ortile +* @file uwauverror-b-module.h +* @author Alessia Ortile * @version 1.0.0 * * \brief Provides the definition of the class UWAUVError. @@ -45,10 +45,9 @@ #define UWAUVError_MODULE_H #include #include -#include "uwsmeposition.h" +#include "uwsmwpposition.h" #include #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. */ @@ -67,9 +66,9 @@ class UwAUVErrorSendTimer : public UwSendTimer { public: /** - * Conscructor of UwSendTimer class - * @param UwAUVCtrModule *m pointer to an object of type UwAUVCtrModule - */ + * Conscructor of UwSendTimer class + * @param UwAUVCtrModule *m pointer to an object of type UwAUVCtrModule + */ UwAUVErrorSendTimer(UwAUVErrorBModule *m) : UwSendTimer((UwCbrModule*)(m)){ }; }; @@ -88,9 +87,9 @@ class UwAUVErrorBModule : public UwCbrModule { /** * Constructor with position setting of UwAUVModule class. * - * @param UWSMEPosition* p Pointer to the AUV position + * @param UWSMWPPosition* p Pointer to the AUV position */ - UwAUVErrorBModule(UWSMEPosition* p); + UwAUVErrorBModule(UWSMWPPosition* p); /** * Destructor of UwAUVModule class. @@ -98,20 +97,20 @@ class UwAUVErrorBModule : public UwCbrModule { virtual ~UwAUVErrorBModule(); /** - * 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. - * - **/ + * 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. - */ + * 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) ; /** @@ -121,14 +120,6 @@ class UwAUVErrorBModule : public UwCbrModule { */ virtual void recv(Packet*); - /** - * Performs the reception of packets from upper and lower layers. - * - * @param Packet* Pointer to the packet will be received. - * @param Handler* Handler. - */ - virtual void recv(Packet* p, Handler* h); - /** * Reset retransmissions */ @@ -145,16 +136,16 @@ class UwAUVErrorBModule : public UwCbrModule { /** * Sets the position of the AUV * - * @param UWSMEPosition * p Pointer to the AUV position + * @param UWSMWPPosition * p Pointer to the AUV position */ - virtual void setPosition(UWSMEPosition* p); + virtual void setPosition(UWSMWPPosition* p); /** * Returns the position of the AUV * * @return the current AUV position */ - inline UWSMEPosition* getPosition() { return posit; } + inline UWSMWPPosition* getPosition() const { return posit; } /** * Returns the size in byte of a hdr_uwAUV_monitoring packet header. @@ -182,7 +173,7 @@ class UwAUVErrorBModule : public UwCbrModule { enum UWAUV_ACK_POLICY { ACK_PIGGYBACK, ACK_IMMEDIATELY, ACK_PGBK_OR_TO }; - UWSMEPosition* posit; /**< AUV position.*/ + 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 diff --git a/DESERT_Addons/uwauv/uwauverror-module.cc b/DESERT_Addons/uwauv/uwauverror-module.cc index 8dd56021..185c72c1 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.cc +++ b/DESERT_Addons/uwauv/uwauverror-module.cc @@ -27,8 +27,8 @@ // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /** -* @file uwauv-module.cc -* @author Filippo Campagnaro, Alessia Ortile +* @file uwauverror-module.cc +* @author Alessia Ortile * @version 1.0.0 * * \brief Provides the UWAUVError class implementation. @@ -88,8 +88,8 @@ UwAUVErrorModule::UwAUVErrorModule() , speed(0.5) , accuracy(0.001) { - UWSMEPosition p = UWSMEPosition(); - posit=&p; + + posit= new UWSMWPPosition(); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); bind("log_flag_", (int*) &log_flag ); bind("period_", (int*) &period ); @@ -99,7 +99,7 @@ UwAUVErrorModule::UwAUVErrorModule() } -UwAUVErrorModule::UwAUVErrorModule(UWSMEPosition* p) +UwAUVErrorModule::UwAUVErrorModule(UWSMWPPosition* p) : UwCbrModule() , last_sn_confirmed(0) , sn(0) @@ -123,7 +123,7 @@ UwAUVErrorModule::UwAUVErrorModule(UWSMEPosition* p) UwAUVErrorModule::~UwAUVErrorModule() {} -void UwAUVErrorModule::setPosition(UWSMEPosition* p){ +void UwAUVErrorModule::setPosition(UWSMWPPosition* p){ posit = p; } @@ -156,27 +156,32 @@ int UwAUVErrorModule::command(int argc, const char*const* argv) { } else if(argc == 3){ if (strcasecmp(argv[1], "setPosition") == 0) { - UWSMEPosition* p = dynamic_cast (tcl.lookup(argv[2])); - posit=p; - tcl.resultf("%s", "position Setted\n"); - return TCL_OK; + 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])); + 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])); + }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])); + 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])); + }else if (strcasecmp(argv[1], "addDest") == 0) { + posit->addDest(atof(argv[2]),atof(argv[3]),atof(argv[4]),atof(argv[5])); return TCL_OK; } @@ -241,7 +246,7 @@ void UwAUVErrorModule::initPkt(Packet* p) { x_e = posit->getX(); // Save error position y_e = posit->getY(); - posit->setdest(posit->getXdest(),posit->getYdest(),posit->getZdest(),0); //STOP + posit->setDest(posit->getXdest(),posit->getYdest(),posit->getZdest(),0); //STOP posit->setAlarm(true); uwAUVh->x() = x_e; @@ -271,7 +276,7 @@ void UwAUVErrorModule::initPkt(Packet* p) { uwAUVh->y() = y_e; uwAUVh->error() = error_m; this->p = p; - uwAUVh->sn() = ++sn; //++ or no? + uwAUVh->sn() = ++sn; } @@ -287,10 +292,6 @@ void UwAUVErrorModule::initPkt(Packet* p) { } -void UwAUVErrorModule::recv(Packet* p, Handler* h) { - recv(p); -} - void UwAUVErrorModule::recv(Packet* p) { hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); @@ -316,7 +317,7 @@ void UwAUVErrorModule::recv(Packet* p) { if (uwAUVh->error() < 0 ){ posit->setAlarm(false); - posit->setdest(posit->getXdest(),posit->getYdest(),posit->getZdest(),speed); + posit->setDest(posit->getXdest(),posit->getYdest(),posit->getZdest(),speed); sendTmr_.force_cancel(); sendTmr_.resched(period); diff --git a/DESERT_Addons/uwauv/uwauverror-module.h b/DESERT_Addons/uwauv/uwauverror-module.h index a7fa262d..c3834611 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.h +++ b/DESERT_Addons/uwauv/uwauverror-module.h @@ -28,7 +28,7 @@ /** * @file uwauv-module.h -* @author Filippo Campagnaro Alessia Ortile +* @author Alessia Ortile * @version 1.0.0 * * \brief Provides the definition of the class UWAUVError. @@ -45,10 +45,9 @@ #define UWAUVError_MODULE_H #include #include -#include "uwsmeposition.h" +#include "uwsmwpposition.h" #include #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. */ @@ -88,9 +87,9 @@ class UwAUVErrorModule : public UwCbrModule { /** * Constructor with position setting of UwAUVModule class. * - * @param UWSMEPosition* p Pointer to the AUV position + * @param UWSMWPPosition* p Pointer to the AUV position */ - UwAUVErrorModule(UWSMEPosition* p); + UwAUVErrorModule(UWSMWPPosition* p); /** * Destructor of UwAUVModule class. @@ -121,14 +120,6 @@ class UwAUVErrorModule : public UwCbrModule { */ virtual void recv(Packet*); - /** - * Performs the reception of packets from upper and lower layers. - * - * @param Packet* Pointer to the packet will be received. - * @param Handler* Handler. - */ - virtual void recv(Packet* p, Handler* h); - /** * Reset retransmissions */ @@ -145,16 +136,16 @@ class UwAUVErrorModule : public UwCbrModule { /** * Sets the position of the AUV * - * @param UWSMEPosition * p Pointer to the AUV position + * @param UWSMWPPosition * p Pointer to the AUV position */ - virtual void setPosition(UWSMEPosition* p); + virtual void setPosition(UWSMWPPosition* p); /** * Returns the position of the AUV * * @return the current AUV position */ - inline UWSMEPosition* getPosition() { return posit; } + inline UWSMWPPosition* getPosition() const { return posit; } /** * Returns the size in byte of a hdr_uwAUV_monitoring packet header. @@ -180,7 +171,7 @@ class UwAUVErrorModule : public UwCbrModule { protected: - UWSMEPosition* posit; /**< AUV position.*/ + 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 diff --git a/DESERT_Framework/DESERT/Makefile.am b/DESERT_Framework/DESERT/Makefile.am index b23ab573..099d5a23 100644 --- a/DESERT_Framework/DESERT/Makefile.am +++ b/DESERT_Framework/DESERT/Makefile.am @@ -87,7 +87,7 @@ SUBDIRS = m4 \ mobility/uwgmposition \ mobility/uwrandomlib \ mobility/uwsmposition \ - mobility/uwsmeposition \ + mobility/uwsmwpposition \ interference/uwinterference \ interference/uwinterferenceofdm \ propagation/uwoptical_propagation \ diff --git a/DESERT_Framework/DESERT/configure.ac b/DESERT_Framework/DESERT/configure.ac index 7eceaaf3..486fe522 100644 --- a/DESERT_Framework/DESERT/configure.ac +++ b/DESERT_Framework/DESERT/configure.ac @@ -108,7 +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/uwsmeposition' +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' @@ -194,7 +194,7 @@ AC_CONFIG_FILES([ mobility/uwgmposition/Makefile mobility/uwrandomlib/Makefile mobility/uwsmposition/Makefile - mobility/uwsmeposition/Makefile + mobility/uwsmwpposition/Makefile interference/uwinterference/Makefile interference/uwinterferenceofdm/Makefile propagation/uwoptical_propagation/Makefile diff --git a/DESERT_Framework/DESERT/mobility/uwsmeposition/Makefile.am b/DESERT_Framework/DESERT/mobility/uwsmwpposition/Makefile.am similarity index 76% rename from DESERT_Framework/DESERT/mobility/uwsmeposition/Makefile.am rename to DESERT_Framework/DESERT/mobility/uwsmwpposition/Makefile.am index 63939021..93391e40 100644 --- a/DESERT_Framework/DESERT/mobility/uwsmeposition/Makefile.am +++ b/DESERT_Framework/DESERT/mobility/uwsmwpposition/Makefile.am @@ -29,31 +29,31 @@ AM_CXXFLAGS = -Wall -ggdb3 -lib_LTLIBRARIES = libuwsmeposition.la +lib_LTLIBRARIES = libuwsmwpposition.la check_PROGRAMS = SUBDIRS = TESTS = -libuwsmeposition_la_SOURCES = initlib.cpp\ - uwsmeposition-default.tcl\ - uwsmeposition.cpp +libuwsmwpposition_la_SOURCES = initlib.cpp\ + uwsmwpposition-default.tcl\ + uwsmwpposition.cpp -libuwsmeposition_la_CPPFLAGS = @NS_CPPFLAGS@ @NSMIRACLE_CPPFLAGS@ @DESERT_CPPFLAGS@ -libuwsmeposition_la_LDFLAGS = @NS_LDFLAGS@ @NSMIRACLE_LDFLAGS@ @DESERT_LDFLAGS@ -libuwsmeposition_la_LIBADD = @NS_LIBADD@ @NSMIRACLE_LIBADD@ @DESERT_LIBADD@ +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_libuwsmeposition_la_SOURCES = InitTcl.cc +nodist_libuwsmwpposition_la_SOURCES = InitTcl.cc BUILT_SOURCES = InitTcl.cc CLEANFILES = InitTcl.cc -TCL_FILES = uwsmeposition-default.tcl +TCL_FILES = uwsmwpposition-default.tcl InitTcl.cc: Makefile $(TCL_FILES) - cat $(VPATH)/$(TCL_FILES) | @TCL2CPP@ UwSMEPositionTclCode > InitTcl.cc + cat $(VPATH)/$(TCL_FILES) | @TCL2CPP@ UwSMWPPositionTclCode > InitTcl.cc EXTRA_DIST = $(TCL_FILES) diff --git a/DESERT_Framework/DESERT/mobility/uwsmeposition/initlib.cpp b/DESERT_Framework/DESERT/mobility/uwsmwpposition/initlib.cpp similarity index 83% rename from DESERT_Framework/DESERT/mobility/uwsmeposition/initlib.cpp rename to DESERT_Framework/DESERT/mobility/uwsmwpposition/initlib.cpp index edf7c133..7c41e808 100644 --- a/DESERT_Framework/DESERT/mobility/uwsmeposition/initlib.cpp +++ b/DESERT_Framework/DESERT/mobility/uwsmwpposition/initlib.cpp @@ -27,30 +27,30 @@ // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /** - * @file mobility/uwsmeposition/initlib.cpp - * @author Filippo Campagnaro + * @file mobility/uwsmwpposition/initlib.cpp + * @author Alessia Ortile * @version 1.0.0 * - * \brief Provides the initialization of uwsmeposition libraries. + * \brief Provides the initialization of uwsmwpposition libraries. * - * Provides the initialization of uwsmeposition libraries. + * Provides the initialization of uwsmwpposition libraries. */ -#include "uwsmeposition.h" +#include "uwsmwpposition.h" #include -extern EmbeddedTcl UwSMEPositionTclCode; +extern EmbeddedTcl UwSMWPPositionTclCode; extern "C" int -Uwsmeposition_Init() +Uwsmwpposition_Init() { - UwSMEPositionTclCode.load(); + UwSMWPPositionTclCode.load(); return 0; } extern "C" int Cygsmposition_Init() { - Uwsmeposition_Init(); + Uwsmwpposition_Init(); } diff --git a/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition-default.tcl b/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition-default.tcl similarity index 94% rename from DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition-default.tcl rename to DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition-default.tcl index 418fdc21..4aa8f51d 100644 --- a/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition-default.tcl +++ b/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition-default.tcl @@ -26,8 +26,8 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # -# @file uwsmeposition-defaults.tcl -# @author Filippo Campagnaro +# @file uwsmwpposition-defaults.tcl +# @author Alessia Ortile # @version 1.0.0 -Position/UWSME set debug_ 0 +Position/UWSMWP set debug_ 0 diff --git a/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.cpp b/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition.cpp similarity index 69% rename from DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.cpp rename to DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition.cpp index 3ac8dfc3..7071be27 100644 --- a/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.cpp +++ b/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition.cpp @@ -28,80 +28,79 @@ // /** -* @file uwsmeposition.cpp -* @author Filippo Campagnaro +* @file uwsmwpposition.cpp +* @author Alessia Ortile * @version 1.0.0 * -* \brief Provides the UWSMEPosition class implementation. +* \brief Provides the UWSMWPPosition class implementation. * -* Provides the UWSMEPosition class implementation. +* Provides the UWSMWPPosition class implementation. */ #include -#include "uwsmeposition.h" +#include "uwsmwpposition.h" /* ====================================================================== TCL Hooks for the simulator ====================================================================== */ -static class UWSMEPositionClass : public TclClass +static class UWSMWPPositionClass : public TclClass { public: - UWSMEPositionClass() - : TclClass("Position/UWSME") + UWSMWPPositionClass() + : TclClass("Position/UWSMWP") { } TclObject * create(int, const char *const *) { - return (new UWSMEPosition()); + return (new UWSMWPPosition()); } -} class_uwsmeposition; +} class_uwsmwpposition; -UWSMEPosition::UWSMEPosition() +UWSMWPPosition::UWSMWPPosition() : UWSMPosition() , alarm_mode(false) - , exist(false) { bind("debug_", &debug_); } -UWSMEPosition::~UWSMEPosition() +UWSMWPPosition::~UWSMWPPosition() { } int -UWSMEPosition::command(int argc, const char *const *argv) +UWSMWPPosition::command(int argc, const char *const *argv) { Tcl &tcl = Tcl::instance(); if (argc == 6) { - if (strcasecmp(argv[1], "setdest") == 0) { + if (strcasecmp(argv[1], "setDest") == 0) { if (debug_) - cerr << NOW << "UWSMEPosition::command(setdest, " << argv[2] + 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])); + setDest(atof(argv[2]), atof(argv[3]), atof(argv[4]), atof(argv[5])); return TCL_OK; - } else if (strcasecmp(argv[1], "adddest") == 0) { + } else if (strcasecmp(argv[1], "addDest") == 0) { if (debug_) - cerr << NOW << "UWSMEPosition::command(adddest, " << argv[2] + 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])); + 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 (strcasecmp(argv[1], "setDest") == 0) { if (debug_) - cerr << NOW << "UWSMEPosition::command(setdest, " << argv[2] + cerr << NOW << "UWSMWPPosition::command(setDest, " << argv[2] << ", " << argv[3] << ", " << argv[4] << ")" << endl; - setdest(atof(argv[2]), atof(argv[3]), atof(argv[4])); + setDest(atof(argv[2]), atof(argv[3]), atof(argv[4])); return TCL_OK; - }else if (strcasecmp(argv[1], "adddest") == 0) { + }else if (strcasecmp(argv[1], "addDest") == 0) { if (debug_) - cerr << NOW << "UWSMEPosition::command(adddest, " << argv[2] + cerr << NOW << "UWSMWPPosition::command(addDest, " << argv[2] << ", " << argv[3] << ", " << argv[4] << ")" << endl; - adddest(atof(argv[2]), atof(argv[3]), atof(argv[4])); + addDest(atof(argv[2]), atof(argv[3]), atof(argv[4])); return TCL_OK; } } else if (argc == 2) { @@ -115,7 +114,7 @@ UWSMEPosition::command(int argc, const char *const *argv) } void -UWSMEPosition::setdest( +UWSMWPPosition::setDest( double x_dest, double y_dest, double z_dest, double speed_setted) { if (alarm_mode){ @@ -142,7 +141,7 @@ UWSMEPosition::setdest( waypoints.insert(waypoints.begin(),{x_dest,y_dest,z_dest,speed_setted}); if (debug_) - printf("New destionation (%f,%f,%f), skip the queue\n", + printf("New destination (%f,%f,%f), skip the queue\n", x_dest, y_dest, z_dest); @@ -184,7 +183,7 @@ UWSMEPosition::setdest( void -UWSMEPosition::setdest(double x_dest, double y_dest, double z_dest) +UWSMWPPosition::setDest(double x_dest, double y_dest, double z_dest) { if (alarm_mode){ if (debug_) @@ -236,12 +235,12 @@ UWSMEPosition::setdest(double x_dest, double y_dest, double z_dest) } void -UWSMEPosition::adddest( +UWSMWPPosition::addDest( double x_dest, double y_dest, double z_dest, double speed_setted) { if (!waypoints.empty()){ - exist = false; + bool exist = false; for (const auto& vec : waypoints) { // Controlla se le coordinate corrispondono @@ -262,8 +261,7 @@ UWSMEPosition::adddest( }else{ - //waypoints.push_back({x_dest,y_dest,z_dest, speed_setted}); - UWSMEPosition::setdest(x_dest,y_dest,z_dest, speed_setted); + UWSMWPPosition::setDest(x_dest,y_dest,z_dest, speed_setted); if (debug_) printf("Pos (%f,%f,%f), new dest(%f,%f,%f)\n", x_, @@ -272,56 +270,19 @@ UWSMEPosition::adddest( Xdest_, Ydest_, Zdest_); - } - - //waypoints.push_back({x_dest,y_dest,z_dest, speed_setted}); - - /*if (!waypoints.empty()){ - - waypoints.push_back({x_dest,y_dest,z_dest,speed_setted}); - - if (debug_) - printf("New waypoint (%f,%f,%f)\n", - x_dest, - y_dest, - z_dest); - - }else{ - - printf("trg time %f", trgTime_); - printf("dest %f %f %f", Xdest_, Ydest_, Zdest_); - printf("sorg %f %f %f", Xsorg_, Ysorg_, Zsorg_); - printf("now %f %f %f", x_, y_, z_); - - waypoints.push_back({x_dest,y_dest,z_dest,speed_setted}); - - if (debug_) - printf("New waypoint (%f,%f,%f)\n", - x_dest, - y_dest, - z_dest); - - double now = Scheduler::instance().clock(); - update(now); - - - - }*/ - - + } } void -UWSMEPosition::adddest( +UWSMWPPosition::addDest( double x_dest, double y_dest, double z_dest) { if (!waypoints.empty()){ - exist = false; + 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; @@ -340,8 +301,7 @@ UWSMEPosition::adddest( }else{ - //waypoints.push_back({x_dest,y_dest,z_dest}); - UWSMEPosition::setdest(x_dest,y_dest,z_dest); + UWSMWPPosition::setDest(x_dest,y_dest,z_dest); if (debug_) printf("Pos (%f,%f,%f), new dest(%f,%f,%f)\n", @@ -352,42 +312,11 @@ UWSMEPosition::adddest( Ydest_, Zdest_); } - - //waypoints.push_back({x_dest,y_dest,z_dest}); - - /*if (!waypoints.empty()){ - - waypoints.push_back({x_dest,y_dest,z_dest}); - - if (debug_) - printf("New waypoint (%f,%f,%f)\n", - x_dest, - y_dest, - z_dest); - - }else{ - - printf("trg time %f", trgTime_); - printf("dest %f %f %f", Xdest_, Ydest_, Zdest_); - printf("sorg %f %f %f", Xsorg_, Ysorg_, Zsorg_); - printf("now %f %f %f", x_, y_, z_); - - waypoints.push_back({x_dest,y_dest,z_dest}); - - if (debug_) - printf("New waypoint (%f,%f,%f)\n", - x_dest, - y_dest, - z_dest); - - double now = Scheduler::instance().clock(); - update(now); - }*/ } void -UWSMEPosition::update(double now) +UWSMWPPosition::update(double now) { if ((trgTime_ < 0.) || (now < lastUpdateTime_ + 1e-6)) return; @@ -419,9 +348,9 @@ UWSMEPosition::update(double now) if (!waypoints.empty()){ if(waypoints[0].size()>3){ - UWSMEPosition::setdest(waypoints[0][0],waypoints[0][1],waypoints[0][2],waypoints[0][3]); + UWSMWPPosition::setDest(waypoints[0][0],waypoints[0][1],waypoints[0][2],waypoints[0][3]); }else{ - UWSMEPosition::setdest(waypoints[0][0],waypoints[0][1],waypoints[0][2]); + UWSMWPPosition::setDest(waypoints[0][0],waypoints[0][1],waypoints[0][2]); } if (debug_) @@ -492,9 +421,9 @@ UWSMEPosition::update(double now) waypoints[0][2]); if(waypoints[0].size()>3){ - UWSMEPosition::setdest(waypoints[0][0],waypoints[0][1],waypoints[0][2],waypoints[0][3]); + UWSMWPPosition::setDest(waypoints[0][0],waypoints[0][1],waypoints[0][2],waypoints[0][3]); }else{ - UWSMEPosition::setdest(waypoints[0][0],waypoints[0][1],waypoints[0][2]); + UWSMWPPosition::setDest(waypoints[0][0],waypoints[0][1],waypoints[0][2]); } if (debug_) @@ -507,32 +436,6 @@ UWSMEPosition::update(double now) } - - - /*if (!waypoints.empty()){ - - if (debug_) - printf("New destination (%f,%f,%f) setted\n", - waypoints[0][0], - waypoints[0][1], - waypoints[0][2]); - - if(waypoints[0].size()>3){ - - UWSMEPosition::setdest(waypoints[0][0],waypoints[0][1],waypoints[0][2],waypoints[0][3]); - - }else{ - - UWSMEPosition::setdest(waypoints[0][0],waypoints[0][1],waypoints[0][2]); - } - - if (debug_) - printf("New dest (%f,%f,%f) from waypoints list\n", - Xdest_, - Ydest_, - Zdest_); - }*/ - } if (debug_) printf("New pos (%f,%f,%f), dest(%f,%f,%f), source(%f,%f,%f), speed %f sen(%f)=%f\n", @@ -554,7 +457,7 @@ UWSMEPosition::update(double now) } void -UWSMEPosition::setAlarm(bool alarm) +UWSMWPPosition::setAlarm(bool alarm) { alarm_mode = alarm; } diff --git a/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.h b/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition.h similarity index 54% rename from DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.h rename to DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition.h index ed04b603..9bde0031 100644 --- a/DESERT_Framework/DESERT/mobility/uwsmeposition/uwsmeposition.h +++ b/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition.h @@ -28,18 +28,18 @@ // /** - * @file uwsmeposition.h - * @author Filippo Campagnaro + * @file uwsmwpposition.h + * @author Alessia Ortile * @version 1.0.0 * - * \brief Provides the definition of the class UWSMEPosition. + * \brief Provides the definition of the class UWSMWPPosition. * - * Provides the definition of the class UWSMEPosition. + * 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. + * 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 * @@ -56,40 +56,25 @@ #define sgn(x) (((x) == 0.0) ? 0.0 : ((x) / fabs(x))) #define pi (4 * atan(1.0)) -class UWSMEPosition; +class UWSMWPPosition; -/** -* UwSendTimer class is used to handle the scheduling period of UWAUV packets. -*/ -/*class UwDstReachedTimer : public TimerHandler -{ -public: - UwDstReachedTimer(UWSMEPosition *m) : TimerHandler() { - module = m; - } -protected: - virtual void expire(Event *e); - UWSMEPosition *module; -};*/ - - -class UWSMEPosition : public UWSMPosition +class UWSMWPPosition : public UWSMPosition { public: /** * Constructor */ - UWSMEPosition(); + UWSMWPPosition(); /** * Destructor */ - virtual ~UWSMEPosition(); + virtual ~UWSMWPPosition(); /** /** * TCL command interpreter - *
  • setdest <integer value>integer + *
  • setDest <integer value>integer *value>integer value>: * set the movement pattern: the firts two values define the point to be *reached (i.e., the @@ -110,31 +95,73 @@ class UWSMEPosition : public UWSMPosition **/ virtual int command(int argc, const char *const *argv); - virtual void setdest( - double x_dest, double y_dest, double z_dest, double spead); - virtual void adddest( - double x_dest, double y_dest, double z_dest, double spead); + /** + * 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 setdest(double x_dest, double y_dest, double z_dest); + virtual void addDest( + double x_dest, double y_dest, double z_dest, double speed); - virtual void adddest(double x_dest, double y_dest, double z_dest); + /** + * 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 alarm); + 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; - int debug_; - bool alarm_mode; //alarm_mode true block all the application from updating the destination - bool exist; + 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_; }; 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 index a39e7807..00f6b19c 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwauv_error.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwauv_error.tcl @@ -44,10 +44,7 @@ ## ######################################################################################## # ---------------------------------------------------------------------------------- -# This script depicts a very simple but complete stack in which two node_leaders send data -# to a common sink. The second node_leader is used by the first one as a relay to send data to the sink. -# The routes are configured by using UW/STATICROUTING. -# The application used to generate data is UW/CBR. +# This script depicts ...TODO # ---------------------------------------------------------------------------------- # Stack # Node 1 Node 2 Sink @@ -94,7 +91,7 @@ load libuwudp.so load libuwcbr.so load libuwtdma.so load libuwsmposition.so -load libuwsmeposition.so +load libuwsmwpposition.so load libuwinterference.so load libUwmStd.so load libUwmStdPhyBpskTracer.so @@ -322,10 +319,10 @@ for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { $mll_op_asv addentry [$ipif_auv($id1) addr] [$mac_op_auv($id1) addr] } -Position/UWSME debug_ 1 +Position/UWSMWP debug_ 1 # Setup positions -set position_asv [new "Position/UWSME"] +set position_asv [new "Position/UWSMWP"] $position_asv setX_ 0 $position_asv setY_ 0 $position_asv setZ_ -1 @@ -350,7 +347,7 @@ $position_auv(2) setY_ -1 for {set id 0} {$id < $opt(n_auv)} {incr id} { - set position_auv($id) [new "Position/UWSME"] + set position_auv($id) [new "Position/UWSMWP"] $position_auv($id) setZ_ -1000 $auv_app($id) setPosition $position_auv($id) 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 index 30f239fb..d44fdbf7 100644 --- 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 @@ -26,7 +26,7 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # -# Author: Giovanni Toso +# Author: Alessia Ortile # Version: 1.0.0 # NOTE: tcl sample tested on Ubuntu 12.04, 64 bits OS # @@ -44,10 +44,7 @@ ## ######################################################################################## # ---------------------------------------------------------------------------------- -# This script depicts a very simple but complete stack in which two node_leaders send data -# to a common sink. The second node_leader is used by the first one as a relay to send data to the sink. -# The routes are configured by using UW/STATICROUTING. -# The application used to generate data is UW/CBR. +# This script depicts ... TODO # ---------------------------------------------------------------------------------- # Stack # Node 1 Node 2 Sink @@ -94,7 +91,7 @@ load libuwudp.so load libuwcbr.so load libuwtdma.so load libuwsmposition.so -load libuwsmeposition.so +load libuwsmwpposition.so load libuwinterference.so load libUwmStd.so load libUwmStdPhyBpskTracer.so @@ -318,10 +315,10 @@ for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { $mll_op_asv addentry [$ipif_auv($id1) addr] [$mac_op_auv($id1) addr] } -Position/UWSME debug_ 1 +Position/UWSMWP debug_ 1 # Setup positions -set position_asv [new "Position/UWSME"] +set position_asv [new "Position/UWSMWP"] $position_asv setX_ 0 $position_asv setY_ 0 $position_asv setZ_ -1 @@ -346,7 +343,7 @@ $position_auv(2) setY_ -1 for {set id 0} {$id < $opt(n_auv)} {incr id} { - set position_auv($id) [new "Position/UWSME"] + set position_auv($id) [new "Position/UWSMWP"] $position_auv($id) setZ_ -1000 $auv_app($id) setPosition $position_auv($id) From 933885de3530da3ca0bb5edf9c768ad7fe3b41a3 Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Sun, 17 Sep 2023 21:29:34 +0200 Subject: [PATCH 24/36] review correction p2 --- DESERT_Addons/uwauv/Makefile.am | 2 +- DESERT_Addons/uwauv/uwauv-init.tcl | 42 ++++++++-------- DESERT_Addons/uwauv/uwauv-module.cc | 7 ++- DESERT_Addons/uwauv/uwauv-module.h | 8 --- DESERT_Addons/uwauv/uwauvctr-module.cc | 8 +-- DESERT_Addons/uwauv/uwauvctr-module.h | 10 ---- DESERT_Addons/uwauv/uwauvctrer-module.cc | 8 ++- DESERT_Addons/uwauv/uwauvctrer-module.h | 14 +----- ...-module.cc => uwauvctrer-simple-module.cc} | 50 +++++++++---------- ...-b-module.h => uwauvctrer-simple-module.h} | 29 ++++------- DESERT_Addons/uwauv/uwauverror-module.cc | 7 +-- DESERT_Addons/uwauv/uwauverror-module.h | 10 ---- ...-module.cc => uwauverror-simple-module.cc} | 34 ++++++------- ...-b-module.h => uwauverror-simple-module.h} | 24 +++------ .../DESERT/samples/desert_samples/AUV/asv.tcl | 2 +- .../samples/desert_samples/AUV/asv_basic.tcl | 20 ++++---- .../DESERT/samples/desert_samples/AUV/auv.tcl | 2 +- .../samples/desert_samples/AUV/auv_basic.tcl | 22 ++++---- .../desert_samples/AUV/test_uwauv_error.tcl | 46 +++++++++-------- .../AUV/test_uwauv_error_basic.tcl | 47 +++++++++-------- 20 files changed, 165 insertions(+), 227 deletions(-) rename DESERT_Addons/uwauv/{uwauvctrer-b-module.cc => uwauvctrer-simple-module.cc} (85%) rename DESERT_Addons/uwauv/{uwauvctrer-b-module.h => uwauvctrer-simple-module.h} (82%) rename DESERT_Addons/uwauv/{uwauverror-b-module.cc => uwauverror-simple-module.cc} (90%) rename DESERT_Addons/uwauv/{uwauverror-b-module.h => uwauverror-simple-module.h} (85%) diff --git a/DESERT_Addons/uwauv/Makefile.am b/DESERT_Addons/uwauv/Makefile.am index cc7c5082..0a82b2ba 100644 --- a/DESERT_Addons/uwauv/Makefile.am +++ b/DESERT_Addons/uwauv/Makefile.am @@ -31,7 +31,7 @@ AM_CXXFLAGS = -Wall -ggdb3 lib_LTLIBRARIES = libuwauv.la -libuwauv_la_SOURCES = uwauv-module.cc uwauverror-module.cc uwauverror-b-module.cc uwauvctr-module.cc uwauvctrer-module.cc uwauvctrer-b-module.cc uwauv-packet.h initlib.cc +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@ diff --git a/DESERT_Addons/uwauv/uwauv-init.tcl b/DESERT_Addons/uwauv/uwauv-init.tcl index f9c01c4e..75699bec 100644 --- a/DESERT_Addons/uwauv/uwauv-init.tcl +++ b/DESERT_Addons/uwauv/uwauv-init.tcl @@ -94,32 +94,32 @@ Module/UW/AUV/CER instproc init {args} { $self settag "UW/AUV/CER" } -Module/UW/AUV/CEB set packetSize_ 100 -Module/UW/AUV/CEB set period_ 60 -Module/UW/AUV/CEB set destPort_ 0 -Module/UW/AUV/CEB set destAddr_ 0 -Module/UW/AUV/CEB set debug_ 0 -Module/UW/AUV/CEB set PoissonTraffic_ 0 -Module/UW/AUV/CEB set drop_out_of_order_ 1 -Module/UW/AUV/CEB set adaptiveRTO_ 0 - -Module/UW/AUV/CEB instproc init {args} { +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/CEB" + $self settag "UW/AUV/CES" } -Module/UW/AUV/ERB set packetSize_ 100 -Module/UW/AUV/ERB set period_ 60 -Module/UW/AUV/ERB set destPort_ 0 -Module/UW/AUV/ERB set destAddr_ 0 -Module/UW/AUV/ERB set debug_ 0 -Module/UW/AUV/ERB set PoissonTraffic_ 0 -Module/UW/AUV/ERB set drop_out_of_order_ 1 -Module/UW/AUV/ERB set adaptiveRTO_ 0 +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/ERB instproc init {args} { +Module/UW/AUV/ERS instproc init {args} { $self next $args - $self settag "UW/AUV/ERB" + $self settag "UW/AUV/ERS" } diff --git a/DESERT_Addons/uwauv/uwauv-module.cc b/DESERT_Addons/uwauv/uwauv-module.cc index 39b066e9..564062cb 100644 --- a/DESERT_Addons/uwauv/uwauv-module.cc +++ b/DESERT_Addons/uwauv/uwauv-module.cc @@ -92,8 +92,7 @@ UwAUVModule::UwAUVModule() , log_flag(0) , out_file_stats(0) { - UWSMWPPosition p = UWSMWPPosition(); - posit=&p; + posit= new UWSMWPPosition(); bind("ackTimeout_", (double*) &ackTimeout); bind("ackPriority_", (int*) &ackPriority); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); @@ -231,7 +230,7 @@ int UwAUVModule::command(int argc, const char*const* argv) { void UwAUVModule::initPkt(Packet* p) { - hdr_uwAUV_monitoring* uwAUVh = HDR_UWAUV_MONITORING(p); + hdr_uwAUV_monitoring* uwAUVh = hdr_uwAUV_monitoring::access(p); hdr_uwcbr *uwcbrh = HDR_UWCBR(p); uwAUVh->x() = posit->getX(); @@ -258,7 +257,7 @@ void UwAUVModule::initPkt(Packet* p) { void UwAUVModule::recv(Packet* p) { - hdr_uwAUV_ctr* uwAUVh = HDR_UWAUV_CTR(p); + hdr_uwAUV_ctr* uwAUVh = hdr_uwAUV_ctr::access(p); if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { //obsolete packets diff --git a/DESERT_Addons/uwauv/uwauv-module.h b/DESERT_Addons/uwauv/uwauv-module.h index 838ac780..d4a1e513 100644 --- a/DESERT_Addons/uwauv/uwauv-module.h +++ b/DESERT_Addons/uwauv/uwauv-module.h @@ -33,12 +33,6 @@ * * \brief Provides the definition of the class UWAUV. * -* Provides the definition of the class UWAUV, based on UwCbr. -* UWAUV can manage no more than 2^16 packets. If a module generates more -* than 2^16 packets, they will be dropped, according with UwCbr. -* UWAUV sends periodically monitoring packets containing information about -* the current position and acknowledges the last control packet received. -* Each control packet contains the next waypoint that has to be reach. */ #ifndef UWAUV_MODULE_H @@ -51,8 +45,6 @@ #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. */ -#define HDR_UWAUV_MONITORING(p) (hdr_uwAUV_monitoring::access(p)) -#define HDR_UWAUV_CTR(p) (hdr_uwAUV_ctr::access(p)) using namespace std; diff --git a/DESERT_Addons/uwauv/uwauvctr-module.cc b/DESERT_Addons/uwauv/uwauvctr-module.cc index af0e0e68..1954bba1 100644 --- a/DESERT_Addons/uwauv/uwauvctr-module.cc +++ b/DESERT_Addons/uwauv/uwauvctr-module.cc @@ -201,7 +201,7 @@ void UwAUVCtrModule::setPosition(UWSMWPPosition* p){ void UwAUVCtrModule::initPkt(Packet* p) { if(this->p == NULL){ - hdr_uwAUV_ctr* uwAUVh = HDR_UWAUV_CTR(p); + hdr_uwAUV_ctr* uwAUVh = hdr_uwAUV_ctr::access(p); uwAUVh -> x() = newX; uwAUVh->y() = newY; uwAUVh->z() = newZ; @@ -210,7 +210,7 @@ void UwAUVCtrModule::initPkt(Packet* p) { this->p = p; } else{ - hdr_uwAUV_ctr* uwAUVh = HDR_UWAUV_CTR(p); + hdr_uwAUV_ctr* uwAUVh = hdr_uwAUV_ctr::access(p); uwAUVh->x() = newX; uwAUVh->y() = newY; uwAUVh->z() = newZ; @@ -231,7 +231,7 @@ void UwAUVCtrModule::initPkt(Packet* p) { UwCbrModule::initPkt(p); if (debug_) { - hdr_uwAUV_ctr* uwAUVh = HDR_UWAUV_CTR(p); + 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; @@ -240,7 +240,7 @@ void UwAUVCtrModule::initPkt(Packet* p) { void UwAUVCtrModule::recv(Packet* p) { - hdr_uwAUV_monitoring* monitoring = HDR_UWAUV_MONITORING(p); + hdr_uwAUV_monitoring* monitoring = hdr_uwAUV_monitoring::access(p); x_auv = monitoring->x(); y_auv = monitoring->y(); z_auv = monitoring->z(); diff --git a/DESERT_Addons/uwauv/uwauvctr-module.h b/DESERT_Addons/uwauv/uwauvctr-module.h index 6fd28f63..f3474d93 100644 --- a/DESERT_Addons/uwauv/uwauvctr-module.h +++ b/DESERT_Addons/uwauv/uwauvctr-module.h @@ -33,14 +33,6 @@ * * \brief Provides the definition of the class UWAUV. * -* Provides the definition of the class UWAUVCTR, based on UwCbr. -* UWAUVCTR can manage no more than 2^16 packets. If a module generates more -* than 2^16 packets, they will be dropped, according with UwCbr. -* UWAUVCTR sends control packets containing the next waypoint that has to be -* reach by a AUV. In addition it receives monitoring packets containing the current -* AUV position and acks of the sent packets. Whether the ack is not received, the -* control packet is resent, according to the priority. In particular, last waypoint -* transmitted has the highest priority, whereas the others are forgotten.: */ #ifndef UWAUV_CTR_MODULE_H @@ -53,8 +45,6 @@ #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. */ -#define HDR_UWAUV_MONITORING(p) (hdr_uwAUV_monitoring::access(p)) -#define HDR_UWAUV_CTR(p) (hdr_uwAUV_ctr::access(p)) using namespace std; class UwAUVCtrModule; diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.cc b/DESERT_Addons/uwauv/uwauvctrer-module.cc index b1337f5d..4f2608bf 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.cc +++ b/DESERT_Addons/uwauv/uwauvctrer-module.cc @@ -44,9 +44,7 @@ extern packet_t PT_UWCBR; extern packet_t PT_UWAUV; extern packet_t PT_UWAUV_CTR; extern packet_t PT_UWAUV_ERROR; -/** -* Adds the module for UwAUVModuleClass in ns2. -*/ + /** * Class that represents the binding with the tcl configuration script @@ -205,7 +203,7 @@ float UwAUVCtrErModule::getDistance(float x_s,float y_s,float x_d,float y_d){ void UwAUVCtrErModule::initPkt(Packet* p) { - hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); + hdr_uwAUV_error* uwAUVh = hdr_uwAUV_error::access(p); hdr_uwcbr *uwcbrh = HDR_UWCBR(p); bool found = false; @@ -301,7 +299,7 @@ void UwAUVCtrErModule::initPkt(Packet* p) { void UwAUVCtrErModule::recv(Packet* p) { - hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); + hdr_uwAUV_error* uwAUVh = hdr_uwAUV_error::access(p); if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { //obsolete packets if (debug_) { diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.h b/DESERT_Addons/uwauv/uwauvctrer-module.h index 9ba594ce..c5f0d070 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.h +++ b/DESERT_Addons/uwauv/uwauvctrer-module.h @@ -31,16 +31,8 @@ * @author Alessia Ortile * @version 1.0.0 * -* \brief Provides the definition of the class UWAUV. +* \brief Provides the definition of the class UWAUVCtrEr. * -* Provides the definition of the class UWAUVCTR, based on UwCbr. -* UWAUVCTR can manage no more than 2^16 packets. If a module generates more -* than 2^16 packets, they will be dropped, according with UwCbr. -* UWAUVCTR sends control packets containing the next waypoint that has to be -* reach by a AUV. In addition it receives monitoring packets containing the current -* AUV position and acks of the sent packets. Whether the ack is not received, the -* control packet is resent, according to the priority. In particular, last waypoint -* transmitted has the highest priority, whereas the others are forgotten.: */ #ifndef UWAUVError_MODULE_H @@ -54,9 +46,7 @@ #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. */ -#define HDR_UWAUV_MONITORING(p) (hdr_uwAUV_monitoring::access(p)) -#define HDR_UWAUV_CTR(p) (hdr_uwAUV_ctr::access(p)) -#define HDR_UWAUV_ERROR(p) (hdr_uwAUV_error::access(p)) + using namespace std; class UwAUVCtrErModule; diff --git a/DESERT_Addons/uwauv/uwauvctrer-b-module.cc b/DESERT_Addons/uwauv/uwauvctrer-simple-module.cc similarity index 85% rename from DESERT_Addons/uwauv/uwauvctrer-b-module.cc rename to DESERT_Addons/uwauv/uwauvctrer-simple-module.cc index 3dd7562d..25554328 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-b-module.cc +++ b/DESERT_Addons/uwauv/uwauvctrer-simple-module.cc @@ -27,16 +27,16 @@ // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /** -* @file uwauvctrer-b-module.cc +* @file uwauvctrer-simple-module.cc * @author Alessia Ortile * @version 1.0.0 * -* \brief Provides the UWAUVCtrEr class implementation. +* \brief Provides the UWAUVCtrErSimple class implementation. * -* Provides the UWAUVCtrEr class implementation. +* Provides the UWAUVCtrErSimple class implementation. */ -#include "uwauvctrer-b-module.h" +#include "uwauvctrer-simple-module.h" #include #include #include @@ -44,20 +44,16 @@ extern packet_t PT_UWCBR; extern packet_t PT_UWAUV; extern packet_t PT_UWAUV_CTR; extern packet_t PT_UWAUV_ERROR; -/** -* Adds the module for UwAUVModuleClass in ns2. -*/ - /** * Class that represents the binding with the tcl configuration script */ -static class UwAUVCtrErBModuleClass : public TclClass { +static class UwAUVCtrErSimpleModuleClass : public TclClass { public: /** * Constructor of the class */ - UwAUVCtrErBModuleClass() : TclClass("Module/UW/AUV/CEB") { + UwAUVCtrErSimpleModuleClass() : TclClass("Module/UW/AUV/CES") { } /** @@ -65,12 +61,12 @@ static class UwAUVCtrErBModuleClass : public TclClass { * @return Pointer to an TclObject */ TclObject* create(int, const char*const*) { - return (new UwAUVCtrErBModule()); + return (new UwAUVCtrErSimpleModule()); } } class_module_uwAUV_error; -UwAUVCtrErBModule::UwAUVCtrErBModule(UWSMWPPosition* p) +UwAUVCtrErSimpleModule::UwAUVCtrErSimpleModule(UWSMWPPosition* p) : UwCbrModule() , last_sn_confirmed(0) , sn(0) @@ -88,7 +84,7 @@ UwAUVCtrErBModule::UwAUVCtrErBModule(UWSMWPPosition* p) bind("period_", (int*) &period ); } -UwAUVCtrErBModule::UwAUVCtrErBModule() +UwAUVCtrErSimpleModule::UwAUVCtrErSimpleModule() : UwCbrModule() , last_sn_confirmed(0) , sn(0) @@ -108,9 +104,9 @@ UwAUVCtrErBModule::UwAUVCtrErBModule() } -UwAUVCtrErBModule::~UwAUVCtrErBModule() {} +UwAUVCtrErSimpleModule::~UwAUVCtrErSimpleModule() {} -int UwAUVCtrErBModule::command(int argc, const char*const* argv) { +int UwAUVCtrErSimpleModule::command(int argc, const char*const* argv) { Tcl& tcl = Tcl::instance(); if(argc == 2){ if (strcasecmp(argv[1], "getAUVMonheadersize") == 0) { @@ -158,7 +154,7 @@ int UwAUVCtrErBModule::command(int argc, const char*const* argv) { return UwCbrModule::command(argc,argv); } -void UwAUVCtrErBModule::setPosition(UWSMWPPosition* p){ +void UwAUVCtrErSimpleModule::setPosition(UWSMWPPosition* p){ posit = p; x_sorg = posit->getX(); @@ -166,19 +162,19 @@ void UwAUVCtrErBModule::setPosition(UWSMWPPosition* p){ } -void UwAUVCtrErBModule::transmit() { +void UwAUVCtrErSimpleModule::transmit() { sendPkt(); if (debug_) { - std::cout << NOW << " UwAUVCtrErBModule::Sending pkt with period: " << period + std::cout << NOW << " UwAUVCtrErSimpleModule::Sending pkt with period: " << period << std::endl; } sendTmr_.resched(period); } -float UwAUVCtrErBModule::getDistance(float x_s,float y_s,float x_d,float y_d){ +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; @@ -186,9 +182,9 @@ float UwAUVCtrErBModule::getDistance(float x_s,float y_s,float x_d,float y_d){ } -void UwAUVCtrErBModule::initPkt(Packet* p) { +void UwAUVCtrErSimpleModule::initPkt(Packet* p) { - hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); + hdr_uwAUV_error* uwAUVh = hdr_uwAUV_error::access(p); hdr_uwcbr *uwcbrh = HDR_UWCBR(p); bool found = false; @@ -237,7 +233,7 @@ void UwAUVCtrErBModule::initPkt(Packet* p) { } if (debug_) { - std::cout << NOW << " UwAUVCtrErBModule::initPkt(Packet *p) ERROR ("<< x_err << "," << y_err << ") SOLVED" + std::cout << NOW << " UwAUVCtrErSimpleModule::initPkt(Packet *p) ERROR ("<< x_err << "," << y_err << ") SOLVED" << std::endl; } @@ -269,7 +265,7 @@ void UwAUVCtrErBModule::initPkt(Packet* p) { this->p = p; if (debug_) { - std::cout << NOW << " UwAUVCtrErBModule::initPkt(Packet *p) ERROR ("<< x_err << "," << y_err << ") still to solve" + std::cout << NOW << " UwAUVCtrErSimpleModule::initPkt(Packet *p) ERROR ("<< x_err << "," << y_err << ") still to solve" << std::endl; } @@ -290,15 +286,15 @@ void UwAUVCtrErBModule::initPkt(Packet* p) { UwCbrModule::initPkt(p); } -void UwAUVCtrErBModule::recv(Packet* p) { +void UwAUVCtrErSimpleModule::recv(Packet* p) { - hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); + hdr_uwAUV_error* uwAUVh = hdr_uwAUV_error::access(p); bool exist = false; if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { //obsolete packets if (debug_) { - std::cout << NOW << " UwAUVCtrErBModule::old error with sn " + std::cout << NOW << " UwAUVCtrErSimpleModule::old error with sn " << uwAUVh->sn() << " dropped " << std::endl; } @@ -307,7 +303,7 @@ void UwAUVCtrErBModule::recv(Packet* p) { if (uwAUVh->error() == 0){// AUV MARKED IT AS NO ERROR if (debug_) - std::cout << NOW << " UwAUVCtrErBModule:: no error" << std::endl; + std::cout << NOW << " UwAUVCtrErSimpleModule:: no error" << std::endl; }else{ // error diff --git a/DESERT_Addons/uwauv/uwauvctrer-b-module.h b/DESERT_Addons/uwauv/uwauvctrer-simple-module.h similarity index 82% rename from DESERT_Addons/uwauv/uwauvctrer-b-module.h rename to DESERT_Addons/uwauv/uwauvctrer-simple-module.h index 21de9121..c6808bc1 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-b-module.h +++ b/DESERT_Addons/uwauv/uwauvctrer-simple-module.h @@ -31,16 +31,8 @@ * @author Alessia Ortile * @version 1.0.0 * -* \brief Provides the definition of the class UWAUV. +* \brief Provides the definition of the class UWAUVCtrErSimple. * -* Provides the definition of the class UWAUVCTR, based on UwCbr. -* UWAUVCTR can manage no more than 2^16 packets. If a module generates more -* than 2^16 packets, they will be dropped, according with UwCbr. -* UWAUVCTR sends control packets containing the next waypoint that has to be -* reach by a AUV. In addition it receives monitoring packets containing the current -* AUV position and acks of the sent packets. Whether the ack is not received, the -* control packet is resent, according to the priority. In particular, last waypoint -* transmitted has the highest priority, whereas the others are forgotten.: */ #ifndef UWAUVError_MODULE_H @@ -54,11 +46,8 @@ #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. */ -#define HDR_UWAUV_MONITORING(p) (hdr_uwAUV_monitoring::access(p)) -#define HDR_UWAUV_CTR(p) (hdr_uwAUV_ctr::access(p)) -#define HDR_UWAUV_ERROR(p) (hdr_uwAUV_error::access(p)) using namespace std; -class UwAUVCtrErBModule; +class UwAUVCtrErSimpleModule; /** * UwSendTimer class is used to handle the scheduling period of UWAUV packets. @@ -70,7 +59,7 @@ class UwAUVErrorSendTimer : public UwSendTimer { * Conscructor of UwSendTimer class * @param UwAUVCtrModule *m pointer to an object of type UwAUVCtrModule */ - UwAUVErrorSendTimer(UwAUVCtrErBModule *m) : UwSendTimer((UwCbrModule*)(m)){ + UwAUVErrorSendTimer(UwAUVCtrErSimpleModule *m) : UwSendTimer((UwCbrModule*)(m)){ }; }; @@ -78,23 +67,23 @@ class UwAUVErrorSendTimer : public UwSendTimer { /** * UwAUVCtrModule class is used to manage UWAUVCtr packets and to collect statistics about them. */ -class UwAUVCtrErBModule : public UwCbrModule { +class UwAUVCtrErSimpleModule : public UwCbrModule { public: /** * Constructor of UwAUVCtrModule class. */ - UwAUVCtrErBModule(); + UwAUVCtrErSimpleModule(); /** * Constructor of UwAUVCtrModule class with position setting. */ - UwAUVCtrErBModule(UWSMWPPosition* p); + UwAUVCtrErSimpleModule(UWSMWPPosition* p); /** * Destructor of UwAUVCtrModule class. */ - virtual ~UwAUVCtrErBModule(); + virtual ~UwAUVCtrErSimpleModule(); /** * TCL command interpreter. It implements the following OTcl methods: @@ -204,7 +193,7 @@ class UwAUVCtrErBModule : public UwCbrModule { }; -int UwAUVCtrErBModule::alarm_mode = 0; -vector> UwAUVCtrErBModule::alarm_queue = {}; +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 index 185c72c1..f7e3ffe5 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.cc +++ b/DESERT_Addons/uwauv/uwauverror-module.cc @@ -49,9 +49,6 @@ int hdr_uwAUV_error::offset_; /**< Offset used to access in /** * Adds the header for hdr_uwAUVError packets in ns2. */ -/** -* Adds the module for UwAUVModuleClass in ns2. -*/ /** * Class that represents the binding with the tcl configuration script @@ -202,7 +199,7 @@ void UwAUVErrorModule::transmit() { void UwAUVErrorModule::initPkt(Packet* p) { hdr_uwcbr *uwcbrh = HDR_UWCBR(p); - hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); + hdr_uwAUV_error* uwAUVh = hdr_uwAUV_error::access(p); uwAUVh->error() = 0; @@ -294,7 +291,7 @@ void UwAUVErrorModule::initPkt(Packet* p) { void UwAUVErrorModule::recv(Packet* p) { - hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); + hdr_uwAUV_error* uwAUVh = hdr_uwAUV_error::access(p); if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { //obsolete packets diff --git a/DESERT_Addons/uwauv/uwauverror-module.h b/DESERT_Addons/uwauv/uwauverror-module.h index c3834611..da6dddf6 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.h +++ b/DESERT_Addons/uwauv/uwauverror-module.h @@ -32,13 +32,6 @@ * @version 1.0.0 * * \brief Provides the definition of the class UWAUVError. -* -* Provides the definition of the class UWAUVError, based on UwCbr. -* UWAUVError can manage no more than 2^16 packets. If a module generates more -* than 2^16 packets, they will be dropped, according with UwCbr. -* UWAUVError sends periodically monitoring packets containing information about -* the current position and acknowledges the last control packet received. -* Each control packet contains the next waypoint that has to be reach. */ #ifndef UWAUVError_MODULE_H @@ -51,9 +44,6 @@ #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. */ -#define HDR_UWAUV_MONITORING(p) (hdr_uwAUV_monitoring::access(p)) -#define HDR_UWAUV_CTR(p) (hdr_uwAUV_ctr::access(p)) -#define HDR_UWAUV_ERROR(p) (hdr_uwAUV_error::access(p)) using namespace std; diff --git a/DESERT_Addons/uwauv/uwauverror-b-module.cc b/DESERT_Addons/uwauv/uwauverror-simple-module.cc similarity index 90% rename from DESERT_Addons/uwauv/uwauverror-b-module.cc rename to DESERT_Addons/uwauv/uwauverror-simple-module.cc index b6e5288e..b50eb0db 100644 --- a/DESERT_Addons/uwauv/uwauverror-b-module.cc +++ b/DESERT_Addons/uwauv/uwauverror-simple-module.cc @@ -27,15 +27,15 @@ // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /** -* @file uwauverror-b-module.cc +* @file uwauverror-simple-module.cc * @author Alessia Ortile * @version 1.0.0 * -* \brief Provides the UWAUVError class implementation. +* \brief Provides the UWAUVErrorSimple class implementation. * */ -#include "uwauverror-b-module.h" +#include "uwauverror-simple-module.h" #include #include #include @@ -49,13 +49,13 @@ extern packet_t PT_UWAUV_ERROR; /** * Class that represents the binding with the tcl configuration script */ -static class UwAUVErrorBModuleClass : public TclClass { +static class UwAUVErrorSimpleModuleClass : public TclClass { public: /** * Constructor of the class */ - UwAUVErrorBModuleClass() : TclClass("Module/UW/AUV/ERB") { + UwAUVErrorSimpleModuleClass() : TclClass("Module/UW/AUV/ERS") { } /** @@ -63,13 +63,13 @@ static class UwAUVErrorBModuleClass : public TclClass { * @return Pointer to an TclObject */ TclObject* create(int, const char*const*) { - return (new UwAUVErrorBModule()); + return (new UwAUVErrorSimpleModule()); } } class_module_uwAUV; -UwAUVErrorBModule::UwAUVErrorBModule() +UwAUVErrorSimpleModule::UwAUVErrorSimpleModule() : UwCbrModule() , last_sn_confirmed(0) , sn(0) @@ -91,7 +91,7 @@ UwAUVErrorBModule::UwAUVErrorBModule() } -UwAUVErrorBModule::UwAUVErrorBModule(UWSMWPPosition* p) +UwAUVErrorSimpleModule::UwAUVErrorSimpleModule(UWSMWPPosition* p) : UwCbrModule() , last_sn_confirmed(0) , sn(0) @@ -113,13 +113,13 @@ UwAUVErrorBModule::UwAUVErrorBModule(UWSMWPPosition* p) } -UwAUVErrorBModule::~UwAUVErrorBModule() {} +UwAUVErrorSimpleModule::~UwAUVErrorSimpleModule() {} -void UwAUVErrorBModule::setPosition(UWSMWPPosition* p){ +void UwAUVErrorSimpleModule::setPosition(UWSMWPPosition* p){ posit = p; } -int UwAUVErrorBModule::command(int argc, const char*const* argv) { +int UwAUVErrorSimpleModule::command(int argc, const char*const* argv) { Tcl& tcl = Tcl::instance(); if(argc == 2){ if (strcasecmp(argv[1], "getAUVMonheadersize") == 0) { @@ -182,11 +182,11 @@ int UwAUVErrorBModule::command(int argc, const char*const* argv) { return UwCbrModule::command(argc,argv); } -void UwAUVErrorBModule::transmit() { +void UwAUVErrorSimpleModule::transmit() { sendPkt(); if (debug_) { - std::cout << NOW << " UwAUVErrorBModule::Sending pkt with period: " << period + std::cout << NOW << " UwAUVErrorSimpleModule::Sending pkt with period: " << period << std::endl; } @@ -194,10 +194,10 @@ void UwAUVErrorBModule::transmit() { sendTmr_.resched(period); } -void UwAUVErrorBModule::initPkt(Packet* p) { +void UwAUVErrorSimpleModule::initPkt(Packet* p) { hdr_uwcbr *uwcbrh = HDR_UWCBR(p); - hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); + hdr_uwAUV_error* uwAUVh = hdr_uwAUV_error::access(p); uwAUVh->error() = 0; @@ -292,9 +292,9 @@ void UwAUVErrorBModule::initPkt(Packet* p) { } -void UwAUVErrorBModule::recv(Packet* p) { +void UwAUVErrorSimpleModule::recv(Packet* p) { - hdr_uwAUV_error* uwAUVh = HDR_UWAUV_ERROR(p); + hdr_uwAUV_error* uwAUVh = hdr_uwAUV_error::access(p); if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { //obsolete packets diff --git a/DESERT_Addons/uwauv/uwauverror-b-module.h b/DESERT_Addons/uwauv/uwauverror-simple-module.h similarity index 85% rename from DESERT_Addons/uwauv/uwauverror-b-module.h rename to DESERT_Addons/uwauv/uwauverror-simple-module.h index a8a3025a..69d8b46d 100644 --- a/DESERT_Addons/uwauv/uwauverror-b-module.h +++ b/DESERT_Addons/uwauv/uwauverror-simple-module.h @@ -31,14 +31,7 @@ * @author Alessia Ortile * @version 1.0.0 * -* \brief Provides the definition of the class UWAUVError. -* -* Provides the definition of the class UWAUVError, based on UwCbr. -* UWAUVError can manage no more than 2^16 packets. If a module generates more -* than 2^16 packets, they will be dropped, according with UwCbr. -* UWAUVError sends periodically monitoring packets containing information about -* the current position and acknowledges the last control packet received. -* Each control packet contains the next waypoint that has to be reach. +* \brief Provides the definition of the class UWAUVErrorSimple. */ #ifndef UWAUVError_MODULE_H @@ -51,13 +44,10 @@ #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. */ -#define HDR_UWAUV_MONITORING(p) (hdr_uwAUV_monitoring::access(p)) -#define HDR_UWAUV_CTR(p) (hdr_uwAUV_ctr::access(p)) -#define HDR_UWAUV_ERROR(p) (hdr_uwAUV_error::access(p)) using namespace std; -class UwAUVErrorBModule; +class UwAUVErrorSimpleModule; /** * UwSendTimer class is used to handle the scheduling period of UWAUV packets. @@ -69,32 +59,32 @@ class UwAUVErrorSendTimer : public UwSendTimer { * Conscructor of UwSendTimer class * @param UwAUVCtrModule *m pointer to an object of type UwAUVCtrModule */ - UwAUVErrorSendTimer(UwAUVErrorBModule *m) : UwSendTimer((UwCbrModule*)(m)){ + UwAUVErrorSendTimer(UwAUVErrorSimpleModule *m) : UwSendTimer((UwCbrModule*)(m)){ }; }; /** * UwAUVModule class is used to manage UWAUV packets and to collect statistics about them. */ -class UwAUVErrorBModule : public UwCbrModule { +class UwAUVErrorSimpleModule : public UwCbrModule { public: /** * Default Constructor of UwAUVModule class. */ - UwAUVErrorBModule(); + UwAUVErrorSimpleModule(); /** * Constructor with position setting of UwAUVModule class. * * @param UWSMWPPosition* p Pointer to the AUV position */ - UwAUVErrorBModule(UWSMWPPosition* p); + UwAUVErrorSimpleModule(UWSMWPPosition* p); /** * Destructor of UwAUVModule class. */ - virtual ~UwAUVErrorBModule(); + virtual ~UwAUVErrorSimpleModule(); /** * TCL command interpreter. It implements the following OTcl methods: diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl index 799df187..2ab84eee 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl @@ -25,7 +25,7 @@ proc createASV { id } { 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_ 1 + Module/UW/AUV/CER set debug_ 0 Module/UW/AUV/CER set log_flag_ 1 Module/UW/AUV/CER set sigma_ $opt(variance) Module/UW/AUV/CER set th_ne_ [expr 1 - $opt(e_prob)] diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv_basic.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv_basic.tcl index 74c6735a..bd8f79cb 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv_basic.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv_basic.tcl @@ -21,19 +21,19 @@ proc createASV { id } { } # TRAFFICO 3: ERROR: AUV --> ASV - Module/UW/AUV/CEB set packetSize_ $opt(pktsize) - Module/UW/AUV/CEB set period_ 60 - Module/UW/AUV/CEB set PoissonTraffic_ 0 - Module/UW/AUV/CEB set traffic_type_ 3 - Module/UW/AUV/CEB set debug_ 0 - Module/UW/AUV/CEB set log_flag_ 1 - Module/UW/AUV/CEB set errrop_ $opt(e_prob) - Module/UW/AUV/CEB set sigma_ $opt(variance) - Module/UW/AUV/CEB set accuracy_ $opt(accuracy) + 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_flag_ 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/CEB] + set asv_err($id1) [new Module/UW/AUV/CES] } set udp_asv [new Module/UW/UDP] diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl index d62327bd..40d2ecf9 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl @@ -20,7 +20,7 @@ proc createAUV { id } { 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_ 1 + Module/UW/AUV/ERR set debug_ 0 Module/UW/AUV/ERR set log_flag_ 1 Module/UW/AUV/ERR set sigma_ $opt(variance) Module/UW/AUV/ERR set th_ne_ [expr 1 - $opt(e_prob)] diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv_basic.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv_basic.tcl index 50725282..9f4b8e3a 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv_basic.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv_basic.tcl @@ -16,17 +16,17 @@ proc createAUV { id } { # TRAFFICO 3: ERROR AUV --> ASV set node_auv($id) [$ns create-M_Node $opt(tracefile) $opt(cltracefile)] - Module/UW/AUV/ERB set packetSize_ $opt(pktsize) - Module/UW/AUV/ERB set period_ $opt(period) - Module/UW/AUV/ERB set PoissonTraffic_ 0 - Module/UW/AUV/ERB set traffic_type_ 3 - Module/UW/AUV/ERB set debug_ 0 - Module/UW/AUV/ERB set log_flag_ 1 - Module/UW/AUV/ERB set errrop_ $opt(e_prob) - Module/UW/AUV/ERB set sigma_ $opt(variance) - Module/UW/AUV/ERB set accuracy_ $opt(accuracy) - - set auv_err($id) [new Module/UW/AUV/ERB] + 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_flag_ 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] 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 index 00f6b19c..739554f8 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwauv_error.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwauv_error.tcl @@ -44,29 +44,33 @@ ## ######################################################################################## # ---------------------------------------------------------------------------------- -# This script depicts ...TODO +# 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 -# Node 1 Node 2 Sink -# +--------------------------+ +--------------------------+ +-------------+------------+ -# | 7. UW/CBR | | 7. UW/CBR | | 7. UW/CBR | UW/CBR | -# +--------------------------+ +--------------------------+ +-------------+------------+ -# | 6. UW/UDP | | 6. UW/UDP | | 6. UW/UDP | -# +--------------------------+ +--------------------------+ +--------------------------+ -# | 5. UW/STATICROUTING | | 5. UW/STATICROUTING | | 5. UW/STATICROUTING | -# +--------------------------+ +--------------------------+ +--------------------------+ -# | 4. UW/IP | | 4. UW/IP | | 4. UW/IP | -# +--------------------------+ +--------------------------+ +--------------------------+ -# | 3. UW/MLL | | 3. UW/MLL | | 3. UW/MLL | -# +--------------------------+ +--------------------------+ +--------------------------+ -# | 2. UW/CSMA_ALOHA | | 2. UW/CSMA_ALOHA | | 2. UW/CSMA_ALOHA | -# +--------------------------+ +--------------------------+ +--------------------------+ -# | 1. Module/MPhy/BPSK | | 1. Module/MPhy/BPSK | | 1. Module/MPhy/BPSK | -# +--------------------------+ +--------------------------+ +--------------------------+ -# | | | | | | -# +----------------------------------------------------------------------------------------+ -# | UnderwaterChannel | -# +----------------------------------------------------------------------------------------+ +# 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 # ###################################### 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 index d44fdbf7..e9239ace 100644 --- 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 @@ -44,30 +44,33 @@ ## ######################################################################################## # ---------------------------------------------------------------------------------- -# This script depicts ... TODO +# 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 -# Node 1 Node 2 Sink -# +--------------------------+ +--------------------------+ +-------------+------------+ -# | 7. UW/CBR | | 7. UW/CBR | | 7. UW/CBR | UW/CBR | -# +--------------------------+ +--------------------------+ +-------------+------------+ -# | 6. UW/UDP | | 6. UW/UDP | | 6. UW/UDP | -# +--------------------------+ +--------------------------+ +--------------------------+ -# | 5. UW/STATICROUTING | | 5. UW/STATICROUTING | | 5. UW/STATICROUTING | -# +--------------------------+ +--------------------------+ +--------------------------+ -# | 4. UW/IP | | 4. UW/IP | | 4. UW/IP | -# +--------------------------+ +--------------------------+ +--------------------------+ -# | 3. UW/MLL | | 3. UW/MLL | | 3. UW/MLL | -# +--------------------------+ +--------------------------+ +--------------------------+ -# | 2. UW/CSMA_ALOHA | | 2. UW/CSMA_ALOHA | | 2. UW/CSMA_ALOHA | -# +--------------------------+ +--------------------------+ +--------------------------+ -# | 1. Module/MPhy/BPSK | | 1. Module/MPhy/BPSK | | 1. Module/MPhy/BPSK | -# +--------------------------+ +--------------------------+ +--------------------------+ -# | | | | | | -# +----------------------------------------------------------------------------------------+ -# | UnderwaterChannel | -# +----------------------------------------------------------------------------------------+ -###################################### +# 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 From a027250964efb41708c60f1d2b3f5ed71b590d7f Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Thu, 19 Oct 2023 13:16:39 +0200 Subject: [PATCH 25/36] review correction p3 --- DESERT_Addons/uwauv/Makefile.am | 2 +- DESERT_Addons/uwauv/configure.ac | 2 +- DESERT_Addons/uwauv/initlib.cc | 2 +- DESERT_Addons/uwauv/uwauv-init.tcl | 4 +- DESERT_Addons/uwauv/uwauv-module.cc | 86 ++++--- DESERT_Addons/uwauv/uwauv-module.h | 6 +- DESERT_Addons/uwauv/uwauv-packet.h | 2 +- DESERT_Addons/uwauv/uwauvctr-module.cc | 27 +-- DESERT_Addons/uwauv/uwauvctr-module.h | 4 +- DESERT_Addons/uwauv/uwauvctrer-module.cc | 158 +++++++------ DESERT_Addons/uwauv/uwauvctrer-module.h | 5 +- .../uwauv/uwauvctrer-simple-module.cc | 109 ++++----- .../uwauv/uwauvctrer-simple-module.h | 6 +- DESERT_Addons/uwauv/uwauverror-module.cc | 144 ++++++------ DESERT_Addons/uwauv/uwauverror-module.h | 6 +- .../uwauv/uwauverror-simple-module.cc | 82 ++++--- .../uwauv/uwauverror-simple-module.h | 6 +- .../uwsmwpposition/uwsmwpposition.cpp | 215 ++++++++---------- .../mobility/uwsmwpposition/uwsmwpposition.h | 2 +- .../DESERT/samples/desert_samples/AUV/asv.tcl | 2 +- .../samples/desert_samples/AUV/asv_basic.tcl | 2 +- .../DESERT/samples/desert_samples/AUV/auv.tcl | 2 +- .../samples/desert_samples/AUV/auv_basic.tcl | 2 +- 23 files changed, 425 insertions(+), 451 deletions(-) diff --git a/DESERT_Addons/uwauv/Makefile.am b/DESERT_Addons/uwauv/Makefile.am index 0a82b2ba..dcdf5cad 100644 --- a/DESERT_Addons/uwauv/Makefile.am +++ b/DESERT_Addons/uwauv/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright (c) 2007 Regents of the SIGNET lab, University of Padova. +# 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 diff --git a/DESERT_Addons/uwauv/configure.ac b/DESERT_Addons/uwauv/configure.ac index 92b0acc1..58f6d911 100644 --- a/DESERT_Addons/uwauv/configure.ac +++ b/DESERT_Addons/uwauv/configure.ac @@ -1,5 +1,5 @@ # -# Copyright (c) 2014 Regents of the SIGNET lab, University of Padova. +# 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 diff --git a/DESERT_Addons/uwauv/initlib.cc b/DESERT_Addons/uwauv/initlib.cc index c137a3b4..8599dee8 100644 --- a/DESERT_Addons/uwauv/initlib.cc +++ b/DESERT_Addons/uwauv/initlib.cc @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Regents of the SIGNET lab, University of Padova. +// 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 diff --git a/DESERT_Addons/uwauv/uwauv-init.tcl b/DESERT_Addons/uwauv/uwauv-init.tcl index 75699bec..532cb833 100644 --- a/DESERT_Addons/uwauv/uwauv-init.tcl +++ b/DESERT_Addons/uwauv/uwauv-init.tcl @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 Regents of the SIGNET lab, University of Padova. +# 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 @@ -27,7 +27,7 @@ # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # @file uwauv-defaults.tcl -# @author Filippo Campagnaro Alessia Ortile +# @author Alessia Ortile # @version 1.0.0 PacketHeaderManager set tab_(PacketHeader/UWAUV) 1 diff --git a/DESERT_Addons/uwauv/uwauv-module.cc b/DESERT_Addons/uwauv/uwauv-module.cc index 564062cb..73f9766a 100644 --- a/DESERT_Addons/uwauv/uwauv-module.cc +++ b/DESERT_Addons/uwauv/uwauv-module.cc @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Regents of the SIGNET lab, University of Padova. +// 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 @@ -89,14 +89,14 @@ UwAUVModule::UwAUVModule() , ackPriority(0) , ackNotPgbk(0) , drop_old_waypoints(0) - , log_flag(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_flag_", (int*) &log_flag ); + 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; @@ -115,14 +115,14 @@ UwAUVModule::UwAUVModule(UWSMWPPosition* p) , ackPriority(0) , ackNotPgbk(0) , drop_old_waypoints(0) - , log_flag(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_flag_", (int*) &log_flag ); + 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; @@ -144,29 +144,23 @@ int UwAUVModule::command(int argc, const char*const* argv) { if (strcasecmp(argv[1], "getAUVMonheadersize") == 0) { tcl.resultf("%d", getAUVMonHeaderSize()); return TCL_OK; - } - else if(strcasecmp(argv[1], "getAUVctrheadersize") == 0) { + } else if(strcasecmp(argv[1], "getAUVctrheadersize") == 0) { tcl.resultf("%d", getAUVCTRHeaderSize()); return TCL_OK; - } - else if(strcasecmp(argv[1], "getX") == 0) { + } else if(strcasecmp(argv[1], "getX") == 0) { tcl.resultf("%f", posit->getX()); return TCL_OK; - } - else if(strcasecmp(argv[1], "getY") == 0) { + } else if(strcasecmp(argv[1], "getY") == 0) { tcl.resultf("%f", posit->getY()); return TCL_OK; - } - else if(strcasecmp(argv[1], "getZ") == 0) { + } else if(strcasecmp(argv[1], "getZ") == 0) { tcl.resultf("%f", posit->getZ()); return TCL_OK; - } - else if(strcasecmp(argv[1], "getAckNotPgbk") == 0) { + } else if(strcasecmp(argv[1], "getAckNotPgbk") == 0) { tcl.resultf("%d", ackNotPgbk); return TCL_OK; } - } - else if(argc == 3){ + } else if(argc == 3){ if (strcasecmp(argv[1], "setPosition") == 0) { UWSMWPPosition* p = dynamic_cast (tcl.lookup(argv[2])); @@ -175,7 +169,7 @@ int UwAUVModule::command(int argc, const char*const* argv) { posit=p; tcl.resultf("%s", "position Setted\n"); return TCL_OK; - }else{ + } else { tcl.resultf("%s", "Invalid position\n"); return TCL_ERROR; } @@ -193,8 +187,8 @@ int UwAUVModule::command(int argc, const char*const* argv) { if (atof(argv[2]) == 3) { ackPolicy = ACK_PGBK_OR_TO; return TCL_OK; - }else{ - cerr<<"Plicy not supported" << std::endl; + } else { + cerr<<"Policy not supported" << std::endl; return TCL_ERROR; } } @@ -206,17 +200,15 @@ int UwAUVModule::command(int argc, const char*const* argv) { ackPriority = atof(argv[2]); return TCL_OK; } - } - else if(argc == 5){ + } 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) { + } 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){ + } 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; @@ -259,7 +251,8 @@ void UwAUVModule::recv(Packet* p) { hdr_uwAUV_ctr* uwAUVh = hdr_uwAUV_ctr::access(p); - if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { //obsolete packets + //obsolete packets + if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { if (debug_) { std::cout << NOW << " UwAUVModule::old waypoint with sn " @@ -276,7 +269,7 @@ void UwAUVModule::recv(Packet* p) { ack = last_sn_confirmed+1; priority_ = (char) ackPriority; - if (log_flag == 1) { + 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() @@ -287,24 +280,13 @@ void UwAUVModule::recv(Packet* p) { if (debug_) std::cout << NOW << " UwAUVModule::recv(Packet *p) AUV received new " - "way point: X = " << uwAUVh->x() << ", Y = " << uwAUVh->y() + << "way point: X = " << uwAUVh->x() << ", Y = " << uwAUVh->y() << ", Z = " << uwAUVh->z()<< std::endl; UwCbrModule::recv(p); - if (ackPolicy == ACK_IMMEDIATELY) { - - if (ackPriority == 0) { - UwCbrModule::sendPkt(); - if (debug_) - cout << NOW << " ACK sent immediately with standard priority " - << std::endl; - } else { - UwCbrModule::sendPktHighPriority(); - if (debug_) - cout << NOW << " ACK sent immediately with high priority " - << std::endl; - } + if (ackPolicy == ACK_IMMEDIATELY) { + sendAck(); } if (ackPolicy == ACK_PGBK_OR_TO) { @@ -317,14 +299,26 @@ void UwAUVModule::sendAck() { ackNotPgbk++; if (ackPriority == 0) { UwCbrModule::sendPkt(); - if (debug_) - cout << NOW << " ACK timeout expired, ACK sent with standard " + 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_) - cout << NOW << " ACK timeout expired, ACK sent with high priority " - << std::endl; + 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 index d4a1e513..2aa308c3 100644 --- a/DESERT_Addons/uwauv/uwauv-module.h +++ b/DESERT_Addons/uwauv/uwauv-module.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Regents of the SIGNET lab, University of Padova. +// 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 @@ -46,8 +46,6 @@ #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. */ -using namespace std; - class UwAUVModule; /** @@ -169,7 +167,7 @@ class UwAUVModule : public UwCbrModule { lower or equal than last_sn_confirmed.*/ - int log_flag; /**< Flag to enable log file writing.*/ + int log_on_file; /**< Flag to enable log file writing.*/ std::ofstream out_file_stats; /**< Output stream for the textual file of debug */ }; diff --git a/DESERT_Addons/uwauv/uwauv-packet.h b/DESERT_Addons/uwauv/uwauv-packet.h index 20dfb16d..ce343516 100644 --- a/DESERT_Addons/uwauv/uwauv-packet.h +++ b/DESERT_Addons/uwauv/uwauv-packet.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2014 Regents of the SIGNET lab, University of Padova. +// 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 diff --git a/DESERT_Addons/uwauv/uwauvctr-module.cc b/DESERT_Addons/uwauv/uwauvctr-module.cc index 1954bba1..2d6e1f62 100644 --- a/DESERT_Addons/uwauv/uwauvctr-module.cc +++ b/DESERT_Addons/uwauv/uwauvctr-module.cc @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Regents of the SIGNET lab, University of Padova. +// 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 @@ -116,32 +116,27 @@ int UwAUVCtrModule::command(int argc, const char*const* argv) { if (strcasecmp(argv[1], "getAUVMonheadersize") == 0) { tcl.resultf("%d", this->getAUVMonHeaderSize()); return TCL_OK; - } - else if(strcasecmp(argv[1], "getAUVctrheadersize") == 0) { + } else if(strcasecmp(argv[1], "getAUVctrheadersize") == 0) { tcl.resultf("%d", this->getAUVCTRHeaderSize()); return TCL_OK; - } - else if(strcasecmp(argv[1], "getX") == 0) { + } else if(strcasecmp(argv[1], "getX") == 0) { tcl.resultf("%f", posit->getX()); return TCL_OK; - } - else if(strcasecmp(argv[1], "getY") == 0) { + } else if(strcasecmp(argv[1], "getY") == 0) { tcl.resultf("%f", posit->getY()); return TCL_OK; - } - else if(strcasecmp(argv[1], "getZ") == 0) { + } else if(strcasecmp(argv[1], "getZ") == 0) { tcl.resultf("%f", posit->getZ()); return TCL_OK; } - } - else if(argc == 3){ + } 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{ + } else { tcl.resultf("%s", "Invalid position\n"); return TCL_ERROR; } @@ -153,8 +148,7 @@ int UwAUVCtrModule::command(int argc, const char*const* argv) { adaptiveRTO_parameter = atof(argv[2]); return TCL_OK; } - } - else if(argc == 5){ + } else if(argc == 5){ if (strcasecmp(argv[1], "sendPosition") == 0) { newX = atof(argv[2]); newY = atof(argv[3]); @@ -164,7 +158,7 @@ int UwAUVCtrModule::command(int argc, const char*const* argv) { tcl.resultf("%s", "position Setted"); return TCL_OK; } - }else if(argc == 6){ + } else if(argc == 6){ if (strcasecmp(argv[1], "sendPosition") == 0) { newX = atof(argv[2]); newY = atof(argv[3]); @@ -208,8 +202,7 @@ void UwAUVCtrModule::initPkt(Packet* p) { uwAUVh->speed() = speed; uwAUVh->sn() = ++sn; this->p = p; - } - else{ + } else { hdr_uwAUV_ctr* uwAUVh = hdr_uwAUV_ctr::access(p); uwAUVh->x() = newX; uwAUVh->y() = newY; diff --git a/DESERT_Addons/uwauv/uwauvctr-module.h b/DESERT_Addons/uwauv/uwauvctr-module.h index f3474d93..95672caf 100644 --- a/DESERT_Addons/uwauv/uwauvctr-module.h +++ b/DESERT_Addons/uwauv/uwauvctr-module.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Regents of the SIGNET lab, University of Padova. +// 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 @@ -45,7 +45,7 @@ #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. */ -using namespace std; + class UwAUVCtrModule; /** diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.cc b/DESERT_Addons/uwauv/uwauvctrer-module.cc index 4f2608bf..bf00808c 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.cc +++ b/DESERT_Addons/uwauv/uwauvctrer-module.cc @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Regents of the SIGNET lab, University of Padova. +// 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 @@ -73,7 +73,7 @@ UwAUVCtrErModule::UwAUVCtrErModule(UWSMWPPosition* p) , last_sn_confirmed(0) , sn(0) , drop_old_waypoints(1) - , log_flag(0) + , log_on_file(0) , period(60) , speed(1.5) , accuracy(0.001) @@ -83,7 +83,7 @@ UwAUVCtrErModule::UwAUVCtrErModule(UWSMWPPosition* p) y_sorg = posit->getY(); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); - bind("log_flag_", (int*) &log_flag ); + bind("log_on_file_", (int*) &log_on_file ); bind("period_", (int*) &period ); bind("sigma_", (double*) &sigma); bind("th_ne_", (double*) &th_ne ); @@ -96,7 +96,7 @@ UwAUVCtrErModule::UwAUVCtrErModule() , last_sn_confirmed(0) , sn(0) , drop_old_waypoints(1) - , log_flag(0) + , log_on_file(0) , period(60) , speed(1.5) , accuracy(0.001) @@ -107,7 +107,7 @@ UwAUVCtrErModule::UwAUVCtrErModule() y_sorg = posit->getY(); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); - bind("log_flag_", (int*) &log_flag ); + bind("log_on_file_", (int*) &log_on_file ); bind("period_", (int*) &period ); bind("sigma_", (double*) &sigma); bind("th_ne_", (double*) &th_ne ); @@ -123,40 +123,34 @@ int UwAUVCtrErModule::command(int argc, const char*const* argv) { if (strcasecmp(argv[1], "getAUVMonheadersize") == 0) { tcl.resultf("%d", this->getAUVMonHeaderSize()); return TCL_OK; - } - else if(strcasecmp(argv[1], "getAUVctrheadersize") == 0) { + } else if(strcasecmp(argv[1], "getAUVctrheadersize") == 0) { tcl.resultf("%d", this->getAUVCTRHeaderSize()); return TCL_OK; - }else if(strcasecmp(argv[1], "getAUVErrorheadersize") == 0) { + } else if(strcasecmp(argv[1], "getAUVErrorheadersize") == 0) { tcl.resultf("%d", this->getAUVErrorHeaderSize()); return TCL_OK; - } - else if(strcasecmp(argv[1], "getX") == 0) { + } else if(strcasecmp(argv[1], "getX") == 0) { tcl.resultf("%f", posit->getX()); return TCL_OK; - } - else if(strcasecmp(argv[1], "getY") == 0) { + } else if(strcasecmp(argv[1], "getY") == 0) { tcl.resultf("%f", posit->getY()); return TCL_OK; - } - else if(strcasecmp(argv[1], "getZ") == 0) { + } else if(strcasecmp(argv[1], "getZ") == 0) { tcl.resultf("%f", posit->getZ()); return TCL_OK; } - } - else if(argc == 3){ + } 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{ + } else { tcl.resultf("%s", "Invalid position\n"); return TCL_ERROR; } - } else - if (strcasecmp(argv[1], "setSpeed") == 0) { + } else if (strcasecmp(argv[1], "setSpeed") == 0) { speed = atof(argv[2]); return TCL_OK; } @@ -172,7 +166,7 @@ void UwAUVCtrErModule::setPosition(UWSMWPPosition* p){ x_sorg = posit->getX(); y_sorg = posit->getY(); - if (log_flag == 1) { + 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; @@ -186,7 +180,7 @@ void UwAUVCtrErModule::transmit() { sendPkt(); if (debug_) { - std::cout << NOW << " UwAUVCtrErModule::Sending pkt with period: " << period + std::cout << NOW << " UwAUVCtrErModule::Sending pkt with period: " << period << std::endl; } @@ -219,22 +213,25 @@ void UwAUVCtrErModule::initPkt(Packet* p) { this->p = p; if (debug_) - std::cout << NOW << " UwAUVCtrErrModule::initPkt(Packet *p) Error released"<< std::endl; + std::cout << NOW << " UwAUVCtrErrModule::initPkt(Packet *p) Error" + << "released"<< std::endl; - }else if (alarm_mode == 2){ //I need to go there + } else if (alarm_mode == 2){ //I need to go there - if ((getDistance(posit->getX(),posit->getY(),x_err,y_err) == 0.0)){ //If in the right position - + //If in the right position + if ((getDistance(posit->getX(),posit->getY(),x_err,y_err) == 0.0)){ found = true; x_s = x_err; y_s = y_err; if (debug_) - std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p) SV reached the destination"<< std::endl; + std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p) SV" + << "reached the destination"<< std::endl; - - }else if((getDistance(x_sorg,y_sorg,x_err,y_err) < getDistance(posit->getX(),posit->getY(),x_sorg,y_sorg))){ //if the right position // has been already passed + //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; x_s = x_err; @@ -242,7 +239,8 @@ void UwAUVCtrErModule::initPkt(Packet* p) { if (debug_) - std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p) SV has gone too far "<< std::endl; + std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p) SV has gone" + << "too far "<< std::endl; } @@ -255,7 +253,7 @@ void UwAUVCtrErModule::initPkt(Packet* p) { uwAUVh->y() = y_s; this->p = p; - if (log_flag == 1) { + if (log_on_file == 1) { err_log.open("log/error_log_t.csv",std::ios_base::app); err_log << "R,"<< NOW << "," << x_s<<","<getX() << ","<< posit->getY() @@ -273,11 +271,11 @@ void UwAUVCtrErModule::initPkt(Packet* p) { } if (debug_) { - std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) ERROR ("<< x_err << "," << y_err << ") SOLVED" - << std::endl; + std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) ERROR ("<< x_err + << "," << y_err << ") SOLVED" << std::endl; } - }else{ + } else { uwAUVh->error() = 1; uwAUVh->sn() = ++sn; @@ -286,8 +284,8 @@ void UwAUVCtrErModule::initPkt(Packet* p) { this->p = p; if (debug_) { - std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) ERROR ("<< x_err << "," << y_err << ") still to solve" - << std::endl; + std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) ERROR ("<< x_err + << "," << y_err << ") still to solve" << std::endl; } } @@ -301,7 +299,8 @@ void UwAUVCtrErModule::recv(Packet* p) { hdr_uwAUV_error* uwAUVh = hdr_uwAUV_error::access(p); - if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { //obsolete packets + //obsolete packets + if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { if (debug_) { std::cout << NOW << " UwAUVCtrErrModule::old error with sn " << uwAUVh->sn() << " dropped " << std::endl; @@ -312,7 +311,7 @@ void UwAUVCtrErModule::recv(Packet* p) { if (debug_) std::cout << NOW << " UwAUVCtrErrModule:: no error" << std::endl; - }else{ // error of some kind + } else { // error of some kind rcv_queue.push_back({uwAUVh->x(), uwAUVh->y()}); @@ -334,7 +333,8 @@ void UwAUVCtrErModule::recv(Packet* p) { 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]) << "),"; + 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; @@ -342,7 +342,8 @@ void UwAUVCtrErModule::recv(Packet* p) { 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; + std::cout << " updated error("<< (gray_queue[i][2]/gray_queue[i][3]) + << ")" << std::endl; } } @@ -353,8 +354,10 @@ void UwAUVCtrErModule::recv(Packet* p) { 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; + 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; } } @@ -386,26 +389,29 @@ void UwAUVCtrErModule::recv(Packet* p) { alarm_mode = 2; 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; + 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_flag == 1) { + 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 << 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 <<","<x(),uwAUVh->y()}); - if (log_flag == 1) { + 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 << "R,"<< NOW << "," << uwAUVh->x() <<","<< + uwAUVh->y() << ", ON"<< std::endl; err_log.close(); } } - if (log_flag == 1) { + 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 << 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; + 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{ + } else { exists = false; @@ -478,20 +487,23 @@ void UwAUVCtrErModule::recv(Packet* p) { if (!exists){ alarm_queue.push_back({uwAUVh->x(),uwAUVh->y()}); - if (log_flag == 1) { + if (log_on_file == 1) { err_log.open("log/error_log_t.csv",std::ios_base::app); - err_log << "R,"<< NOW << "," << uwAUVh->x() <<","<y()<<", ON"<< std::endl; + 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; + 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{ + } else { //status 0 --> no error int i = 0; @@ -506,14 +518,16 @@ void UwAUVCtrErModule::recv(Packet* p) { x_s = uwAUVh->x(); y_s = uwAUVh->y(); - if (log_flag == 1) { + 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 << "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; + std::cout << NOW << " UwAUVCtrErrModule:: After some tx" + <<"converged to no error" << std::endl; } } @@ -525,16 +539,16 @@ void UwAUVCtrErModule::recv(Packet* p) { } int UwAUVCtrErModule::checkError(double m, int n_pkt, float x, float y){ - - double p_e = std::erfc((((th_ne - (m/n_pkt)) * std::sqrt(n_pkt)) / std::sqrt(2.0)) / sigma)/2; // prob of true error (t_e) greater than th_ne - + + // 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; int status; if (p_e < accuracy){ //if p_e is small enough --> no error status = 0; - }else if (p_e > (1-accuracy)){ + } else if (p_e > (1-accuracy)){ // FOR SURE ERROR status = 2; - }else{ + } else { //I NEED MORE DATA status = 1; } diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.h b/DESERT_Addons/uwauv/uwauvctrer-module.h index c5f0d070..34972a87 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.h +++ b/DESERT_Addons/uwauv/uwauvctrer-module.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Regents of the SIGNET lab, University of Padova. +// 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 @@ -47,7 +47,6 @@ #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. */ -using namespace std; class UwAUVCtrErModule; /** @@ -175,7 +174,7 @@ class UwAUVCtrErModule : public UwCbrModule { float y_s; /**< Y of the last AUV position with an error that has been solved.*/ Packet* p; - int log_flag; + int log_on_file; float x_sorg; float y_sorg; double speed; diff --git a/DESERT_Addons/uwauv/uwauvctrer-simple-module.cc b/DESERT_Addons/uwauv/uwauvctrer-simple-module.cc index 25554328..88e92008 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-simple-module.cc +++ b/DESERT_Addons/uwauv/uwauvctrer-simple-module.cc @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Regents of the SIGNET lab, University of Padova. +// 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 @@ -71,7 +71,7 @@ UwAUVCtrErSimpleModule::UwAUVCtrErSimpleModule(UWSMWPPosition* p) , last_sn_confirmed(0) , sn(0) , drop_old_waypoints(1) - , log_flag(0) + , log_on_file(0) , period(60) , speed(1.5) { @@ -80,7 +80,7 @@ UwAUVCtrErSimpleModule::UwAUVCtrErSimpleModule(UWSMWPPosition* p) y_sorg = posit->getY(); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); - bind("log_flag_", (int*) &log_flag ); + bind("log_on_file_", (int*) &log_on_file ); bind("period_", (int*) &period ); } @@ -89,7 +89,7 @@ UwAUVCtrErSimpleModule::UwAUVCtrErSimpleModule() , last_sn_confirmed(0) , sn(0) , drop_old_waypoints(1) - , log_flag(0) + , log_on_file(0) , period(60) , speed(1.5) @@ -99,7 +99,7 @@ UwAUVCtrErSimpleModule::UwAUVCtrErSimpleModule() y_sorg = posit->getY(); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); - bind("log_flag_", (int*) &log_flag ); + bind("log_on_file_", (int*) &log_on_file ); bind("period_", (int*) &period ); } @@ -112,40 +112,34 @@ int UwAUVCtrErSimpleModule::command(int argc, const char*const* argv) { if (strcasecmp(argv[1], "getAUVMonheadersize") == 0) { tcl.resultf("%d", this->getAUVMonHeaderSize()); return TCL_OK; - } - else if(strcasecmp(argv[1], "getAUVctrheadersize") == 0) { + } else if(strcasecmp(argv[1], "getAUVctrheadersize") == 0) { tcl.resultf("%d", this->getAUVCTRHeaderSize()); return TCL_OK; - }else if(strcasecmp(argv[1], "getAUVErrorheadersize") == 0) { + } else if(strcasecmp(argv[1], "getAUVErrorheadersize") == 0) { tcl.resultf("%d", this->getAUVErrorHeaderSize()); return TCL_OK; - } - else if(strcasecmp(argv[1], "getX") == 0) { + } else if(strcasecmp(argv[1], "getX") == 0) { tcl.resultf("%f", posit->getX()); return TCL_OK; - } - else if(strcasecmp(argv[1], "getY") == 0) { + } else if(strcasecmp(argv[1], "getY") == 0) { tcl.resultf("%f", posit->getY()); return TCL_OK; - } - else if(strcasecmp(argv[1], "getZ") == 0) { + } else if(strcasecmp(argv[1], "getZ") == 0) { tcl.resultf("%f", posit->getZ()); return TCL_OK; } - } - else if(argc == 3){ + } 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{ + } else { tcl.resultf("%s", "Invalid position\n"); return TCL_ERROR; } - } else - if (strcasecmp(argv[1], "setSpeed") == 0) { + } else if (strcasecmp(argv[1], "setSpeed") == 0) { speed = atof(argv[2]); return TCL_OK; } @@ -167,8 +161,8 @@ void UwAUVCtrErSimpleModule::transmit() { sendPkt(); if (debug_) { - std::cout << NOW << " UwAUVCtrErSimpleModule::Sending pkt with period: " << period - << std::endl; + std::cout << NOW << " UwAUVCtrErSimpleModule::Sending pkt with period: " + << period << std::endl; } sendTmr_.resched(period); @@ -192,17 +186,20 @@ void UwAUVCtrErSimpleModule::initPkt(Packet* p) { if (alarm_mode){ - if ((getDistance(posit->getX(),posit->getY(),x_err,y_err) == 0.0)){ //If in the right position + //If in the right position + if ((getDistance(posit->getX(),posit->getY(),x_err,y_err) == 0.0)){ found = true; x_s = x_err; y_s = y_err; if (debug_) - std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p) SV reached the destination"<< std::endl; + std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p)" + << "SV reached the destination"<< std::endl; - - }else if((getDistance(x_sorg,y_sorg,x_err,y_err) < getDistance(posit->getX(),posit->getY(),x_sorg,y_sorg))){ //if the right position // has been already passed + //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; x_s = x_err; @@ -210,7 +207,8 @@ void UwAUVCtrErSimpleModule::initPkt(Packet* p) { if (debug_) - std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p) SV has gone too far "<< std::endl; + std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p) SV" + << "has gone too far "<< std::endl; } @@ -223,7 +221,7 @@ void UwAUVCtrErSimpleModule::initPkt(Packet* p) { uwAUVh->y() = y_s; this->p = p; - if (log_flag == 1) { + if (log_on_file == 1) { pos_log.open("log/position_log.csv",std::ios_base::app); pos_log << NOW << "," << posit->getX() << ","<< posit->getY() @@ -233,8 +231,8 @@ void UwAUVCtrErSimpleModule::initPkt(Packet* p) { } if (debug_) { - std::cout << NOW << " UwAUVCtrErSimpleModule::initPkt(Packet *p) ERROR ("<< x_err << "," << y_err << ") SOLVED" - << std::endl; + 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 @@ -251,12 +249,13 @@ void UwAUVCtrErSimpleModule::initPkt(Packet* p) { 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; + std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) SV" + <<"picked a new error from the queue: X = " << x_err << "," + << "Y = " << y_err<< std::endl; } } - }else{ + } else { uwAUVh->error() = 1; uwAUVh->sn() = sn; @@ -265,15 +264,16 @@ void UwAUVCtrErSimpleModule::initPkt(Packet* p) { this->p = p; if (debug_) { - std::cout << NOW << " UwAUVCtrErSimpleModule::initPkt(Packet *p) ERROR ("<< x_err << "," << y_err << ") still to solve" - << std::endl; + std::cout << NOW << " UwAUVCtrErSimpleModule::initPkt(Packet *p)" + << "ERROR ("<< x_err << "," << y_err << ") still to solve" + << std::endl; } } } - if (log_flag == 1) { + if (log_on_file == 1) { pos_log.open("log/position_log.csv",std::ios_base::app); pos_log << NOW << "," << posit->getX() << ","<< posit->getY() @@ -291,8 +291,8 @@ void UwAUVCtrErSimpleModule::recv(Packet* p) { hdr_uwAUV_error* uwAUVh = hdr_uwAUV_error::access(p); bool exist = false; - - if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { //obsolete packets + //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; @@ -303,9 +303,10 @@ void UwAUVCtrErSimpleModule::recv(Packet* p) { if (uwAUVh->error() == 0){// AUV MARKED IT AS NO ERROR if (debug_) - std::cout << NOW << " UwAUVCtrErSimpleModule:: no error" << std::endl; + std::cout << NOW << " UwAUVCtrErSimpleModule:: no error" + << std::endl; - }else{ // error + } else { // error if (!alarm_mode){ @@ -322,19 +323,21 @@ void UwAUVCtrErSimpleModule::recv(Packet* p) { alarm_mode = 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; + 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_flag == 1) { + 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 << NOW << "," << posit->getX() << ","<< + posit->getY() << ","<< posit->getZ() << std::endl; pos_log.close(); } - }else{ + } else { x_err = alarm_queue[0][0]; y_err = alarm_queue[0][1]; @@ -360,7 +363,7 @@ void UwAUVCtrErSimpleModule::recv(Packet* p) { alarm_queue.erase(alarm_queue.begin()); - if (log_flag == 1) { + if (log_on_file == 1) { pos_log.open("log/position_log.csv",std::ios_base::app); pos_log << NOW << "," << posit->getX() << ","<< posit->getY() @@ -371,12 +374,14 @@ void UwAUVCtrErSimpleModule::recv(Packet* p) { 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; + 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{ + } else { exist = false; @@ -393,8 +398,10 @@ void UwAUVCtrErSimpleModule::recv(Packet* p) { } 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; + 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; } diff --git a/DESERT_Addons/uwauv/uwauvctrer-simple-module.h b/DESERT_Addons/uwauv/uwauvctrer-simple-module.h index c6808bc1..65ce1a8c 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-simple-module.h +++ b/DESERT_Addons/uwauv/uwauvctrer-simple-module.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Regents of the SIGNET lab, University of Padova. +// 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 @@ -46,7 +46,7 @@ #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. */ -using namespace std; + class UwAUVCtrErSimpleModule; /** @@ -177,7 +177,7 @@ class UwAUVCtrErSimpleModule : public UwCbrModule { float y_s; /**< Y of the last AUV position with an error that has been solved.*/ Packet* p; - int log_flag; + int log_on_file; float x_sorg; float y_sorg; double speed; diff --git a/DESERT_Addons/uwauv/uwauverror-module.cc b/DESERT_Addons/uwauv/uwauverror-module.cc index f7e3ffe5..a52b0f32 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.cc +++ b/DESERT_Addons/uwauv/uwauverror-module.cc @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Regents of the SIGNET lab, University of Padova. +// 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 @@ -78,7 +78,7 @@ UwAUVErrorModule::UwAUVErrorModule() , last_sn_confirmed(0) , sn(0) , drop_old_waypoints(1) - , log_flag(0) + , log_on_file(0) , period(60) , error_m(0) , alarm_mode(0) @@ -88,7 +88,7 @@ UwAUVErrorModule::UwAUVErrorModule() posit= new UWSMWPPosition(); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); - bind("log_flag_", (int*) &log_flag ); + bind("log_on_file_", (int*) &log_on_file ); bind("period_", (int*) &period ); bind("sigma_", (double*) &sigma ); bind("th_ne_", (double*) &th_ne ); @@ -101,7 +101,7 @@ UwAUVErrorModule::UwAUVErrorModule(UWSMWPPosition* p) , last_sn_confirmed(0) , sn(0) , drop_old_waypoints(1) - , log_flag(0) + , log_on_file(0) , period(60) , error_m(0) , alarm_mode(0) @@ -110,7 +110,7 @@ UwAUVErrorModule::UwAUVErrorModule(UWSMWPPosition* p) { posit = p; bind("drop_old_waypoints_", (int*) &drop_old_waypoints); - bind("log_flag_", (int*) &log_flag ); + bind("log_on_file_", (int*) &log_on_file ); bind("period_", (int*) &period ); bind("sigma_", (double*) &sigma); bind("th_ne_", (double*) &th_ne ); @@ -130,54 +130,47 @@ int UwAUVErrorModule::command(int argc, const char*const* argv) { if (strcasecmp(argv[1], "getAUVMonheadersize") == 0) { tcl.resultf("%d", getAUVMonHeaderSize()); return TCL_OK; - } - else if(strcasecmp(argv[1], "getAUVctrheadersize") == 0) { + } else if(strcasecmp(argv[1], "getAUVctrheadersize") == 0) { tcl.resultf("%d", getAUVCTRHeaderSize()); return TCL_OK; - }else if(strcasecmp(argv[1], "getAUVErrorheadersize") == 0) { + } else if(strcasecmp(argv[1], "getAUVErrorheadersize") == 0) { tcl.resultf("%d", getAUVErrorHeaderSize()); return TCL_OK; - } - else if(strcasecmp(argv[1], "getX") == 0) { + } else if(strcasecmp(argv[1], "getX") == 0) { tcl.resultf("%f", posit->getX()); return TCL_OK; - } - else if(strcasecmp(argv[1], "getY") == 0) { + } else if(strcasecmp(argv[1], "getY") == 0) { tcl.resultf("%f", posit->getY()); return TCL_OK; - } - else if(strcasecmp(argv[1], "getZ") == 0) { + } else if(strcasecmp(argv[1], "getZ") == 0) { tcl.resultf("%f", posit->getZ()); return TCL_OK; } - } - else if(argc == 3){ + } 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{ + } else { tcl.resultf("%s", "Invalid position\n"); return TCL_ERROR; } } - } - else if(argc == 5){ + } 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) { + } 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){ + } 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) { + } else if (strcasecmp(argv[1], "addDest") == 0) { posit->addDest(atof(argv[2]),atof(argv[3]),atof(argv[4]),atof(argv[5])); return TCL_OK; } @@ -190,8 +183,8 @@ void UwAUVErrorModule::transmit() { sendPkt(); if (debug_) { - std::cout << NOW << " UwAUVErrorModule::Sending pkt with period: " << period - << std::endl; + std::cout << NOW << " UwAUVErrorModule::Sending pkt with period: " << + period << std::endl; } sendTmr_.resched(period); } @@ -211,23 +204,27 @@ void UwAUVErrorModule::initPkt(Packet* p) { if (debug_) { std::cout << NOW << " UwAUVErroModule::initPkt(Packet *p) " - << "Gray Zone error, new measure: "<< error_m <<", true error: "<< t_e << std::endl; + << "Gray Zone error, new measure: "<< error_m <<", true error: " + << t_e << std::endl; } - }else{ + } else { error_m = getErrorMeasure(); if (debug_) { std::cout << NOW << " UwAUVErroModule::initPkt(Packet *p) " - << "New error, measure: "<< error_m <<", true error: "<< t_e << std::endl; + << "New error, measure: "<< error_m <<", true error: "<< t_e + << std::endl; } if(alarm_mode == 1){ // start error timer - if (log_flag == 1) { + 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 << "G,"<< NOW << "," << posit->getX() <<","<< + posit->getY() <<", ON"<< std::endl; err_log.close(); err_log.open("log/error_log.csv",std::ios_base::app); @@ -240,10 +237,11 @@ void UwAUVErrorModule::initPkt(Packet* p) { if (alarm_mode == 1){ - x_e = posit->getX(); // Save error position + x_e = posit->getX(); // Save error position y_e = posit->getY(); - posit->setDest(posit->getXdest(),posit->getYdest(),posit->getZdest(),0); //STOP + //STOP + posit->setDest(posit->getXdest(),posit->getYdest(),posit->getZdest(),0); posit->setAlarm(true); uwAUVh->x() = x_e; @@ -252,22 +250,24 @@ void UwAUVErrorModule::initPkt(Packet* p) { 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; + 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{ + } else { if (debug_) { - std::cout << NOW << " UwAUVErroModule::initPkt(Packet *p) " - << "no error "<<" alarm_mode = " << alarm_mode << std::endl; + std::cout << NOW << " UwAUVErroModule::initPkt(Packet *p) " + << "no error "<<" alarm_mode = " << alarm_mode << std::endl; } } uwAUVh->sn() = ++sn; - }else{ + } else { uwAUVh->x() = x_e; uwAUVh->y() = y_e; @@ -280,7 +280,7 @@ void UwAUVErrorModule::initPkt(Packet* p) { UwCbrModule::initPkt(p); - if (log_flag == 1) { + 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; @@ -293,9 +293,8 @@ void UwAUVErrorModule::recv(Packet* p) { hdr_uwAUV_error* uwAUVh = hdr_uwAUV_error::access(p); - - if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { //obsolete packets - + //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; @@ -309,7 +308,8 @@ void UwAUVErrorModule::recv(Packet* p) { * error < 0 stop tx, there is no error */ - if (alarm_mode && uwAUVh->x() == x_e && uwAUVh->y() == y_e){ //Valid pkt refering to my error + //Valid pkt refering to my error + if (alarm_mode && uwAUVh->x() == x_e && uwAUVh->y() == y_e){ if (uwAUVh->error() < 0 ){ @@ -319,14 +319,16 @@ void UwAUVErrorModule::recv(Packet* p) { sendTmr_.force_cancel(); sendTmr_.resched(period); - if (log_flag == 1) { + 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 << "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 << "OFF,"<< NOW << "," << x_e <<","<< y_e + << std::endl; err_log.close(); if (uwAUVh->error() == -1){ @@ -334,13 +336,15 @@ void UwAUVErrorModule::recv(Packet* p) { 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 << NOW << "," << x_e <<","<< y_e <<",tn" + << std::endl; t_err_log.close(); - }else{ + } 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 << NOW << "," << x_e <<","<< y_e <<",fn" + << std::endl; t_err_log.close(); } @@ -352,25 +356,28 @@ void UwAUVErrorModule::recv(Packet* p) { 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; + 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_flag == 1) { + 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 << NOW << "," << x_e <<","<< y_e <<",tp" + << std::endl; t_err_log.close(); - }else{ + } 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 << NOW << "," << x_e <<","<< y_e <<",fp" + << std::endl; t_err_log.close(); } @@ -378,16 +385,18 @@ void UwAUVErrorModule::recv(Packet* p) { } 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; + 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 + } 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; + std::cout << NOW << " UwAUVErrModule::recv(Packet *p)" + << "MAYBE there is an error ("<< x_e <<","<< y_e <<")"<< + "continue tx"<< std::endl; } } @@ -397,7 +406,7 @@ void UwAUVErrorModule::recv(Packet* p) { UwCbrModule::recv(p); - if (log_flag == 1) { + 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; @@ -422,13 +431,14 @@ double UwAUVErrorModule::getErrorMeasure(){ double m = t_e + noise; // Calculate the error probability - double p_e = std::erfc(((th_ne - m) / std::sqrt(2.0)) / sigma)/2; // prob of true error (t_e) greater than th_ne - - if (p_e > accuracy){ //if p_e is small enough --> no error, otherwise gray zone + // 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{ + } else { if (t_e > th_ne){ - if (log_flag == 1) { + 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(); @@ -438,7 +448,7 @@ double UwAUVErrorModule::getErrorMeasure(){ if (t_e > th_ne){ - if (log_flag == 1) { + 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(); diff --git a/DESERT_Addons/uwauv/uwauverror-module.h b/DESERT_Addons/uwauv/uwauverror-module.h index da6dddf6..c32d9808 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.h +++ b/DESERT_Addons/uwauv/uwauverror-module.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Regents of the SIGNET lab, University of Padova. +// 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 @@ -44,8 +44,6 @@ #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. */ - -using namespace std; class UwAUVErrorModule; @@ -168,7 +166,7 @@ class UwAUVErrorModule : public UwCbrModule { lower or equal than last_sn_confirmed.*/ - int log_flag; /**< Flag to enable log file writing.*/ + int log_on_file; /**< Flag to enable log file writing.*/ Packet* p; int period; std::ofstream out_file_stats; /**< Output stream for the textual file of debug */ diff --git a/DESERT_Addons/uwauv/uwauverror-simple-module.cc b/DESERT_Addons/uwauv/uwauverror-simple-module.cc index b50eb0db..5a090226 100644 --- a/DESERT_Addons/uwauv/uwauverror-simple-module.cc +++ b/DESERT_Addons/uwauv/uwauverror-simple-module.cc @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Regents of the SIGNET lab, University of Padova. +// 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 @@ -74,7 +74,7 @@ UwAUVErrorSimpleModule::UwAUVErrorSimpleModule() , last_sn_confirmed(0) , sn(0) , drop_old_waypoints(1) - , log_flag(0) + , log_on_file(0) , period(60) , error_p(0.001) , alarm_mode(0) @@ -83,7 +83,7 @@ UwAUVErrorSimpleModule::UwAUVErrorSimpleModule() { posit= new UWSMWPPosition(); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); - bind("log_flag_", (int*) &log_flag ); + bind("log_on_file_", (int*) &log_on_file ); bind("period_", (int*) &period ); bind("error_p_", (int*) &error_p ); bind("sigma_", (double*) &sigma); @@ -96,7 +96,7 @@ UwAUVErrorSimpleModule::UwAUVErrorSimpleModule(UWSMWPPosition* p) , last_sn_confirmed(0) , sn(0) , drop_old_waypoints(1) - , log_flag(0) + , log_on_file(0) , period(60) , error_p(0.01) , alarm_mode(0) @@ -105,7 +105,7 @@ UwAUVErrorSimpleModule::UwAUVErrorSimpleModule(UWSMWPPosition* p) { posit = p; bind("drop_old_waypoints_", (int*) &drop_old_waypoints); - bind("log_flag_", (int*) &log_flag ); + bind("log_on_file_", (int*) &log_on_file ); bind("period_", (int*) &period ); bind("error_p_", (int*) &error_p ); bind("sigma_", (double*) &sigma); @@ -125,55 +125,48 @@ int UwAUVErrorSimpleModule::command(int argc, const char*const* argv) { if (strcasecmp(argv[1], "getAUVMonheadersize") == 0) { tcl.resultf("%d", getAUVMonHeaderSize()); return TCL_OK; - } - else if(strcasecmp(argv[1], "getAUVctrheadersize") == 0) { + } else if(strcasecmp(argv[1], "getAUVctrheadersize") == 0) { tcl.resultf("%d", getAUVCTRHeaderSize()); return TCL_OK; - }else if(strcasecmp(argv[1], "getAUVErrorheadersize") == 0) { + } else if(strcasecmp(argv[1], "getAUVErrorheadersize") == 0) { tcl.resultf("%d", getAUVErrorHeaderSize()); return TCL_OK; - } - else if(strcasecmp(argv[1], "getX") == 0) { + } else if(strcasecmp(argv[1], "getX") == 0) { tcl.resultf("%f", posit->getX()); return TCL_OK; - } - else if(strcasecmp(argv[1], "getY") == 0) { + } else if(strcasecmp(argv[1], "getY") == 0) { tcl.resultf("%f", posit->getY()); return TCL_OK; - } - else if(strcasecmp(argv[1], "getZ") == 0) { + } else if(strcasecmp(argv[1], "getZ") == 0) { tcl.resultf("%f", posit->getZ()); return TCL_OK; } - } - else if(argc == 3){ + } 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{ + } else { tcl.resultf("%s", "Invalid position\n"); return TCL_ERROR; } } - } - else if(argc == 5){ + } 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) { + } 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){ + } 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) { + } else if (strcasecmp(argv[1], "addDest") == 0) { posit->addDest(atof(argv[2]),atof(argv[3]),atof(argv[4]),atof(argv[5])); return TCL_OK; } @@ -186,7 +179,7 @@ void UwAUVErrorSimpleModule::transmit() { sendPkt(); if (debug_) { - std::cout << NOW << " UwAUVErrorSimpleModule::Sending pkt with period: " << period + std::cout << NOW << " UwAUVErrorSimpleModule::Sending pkt with period: " << period << std::endl; } @@ -214,10 +207,10 @@ void UwAUVErrorSimpleModule::initPkt(Packet* p) { double m = t_e + noise; - double p_e = std::erfc((((1 - error_p) - m) / std::sqrt(2.0)) / sigma)/2; // prob of true error (t_e) greater than th_ne - + // 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_flag == 1) { + 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(); @@ -238,31 +231,31 @@ void UwAUVErrorSimpleModule::initPkt(Packet* p) { uwAUVh->error() = 1; uwAUVh->sn() = ++sn; - if (log_flag == 1) { + 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_flag == 1) { + 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{ + } 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{ + } else { - if (log_flag == 1) { + 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{ + } 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(); @@ -271,7 +264,7 @@ void UwAUVErrorSimpleModule::initPkt(Packet* p) { } - }else{ + } else { uwAUVh->x() = x_e; uwAUVh->y() = y_e; @@ -283,7 +276,7 @@ void UwAUVErrorSimpleModule::initPkt(Packet* p) { UwCbrModule::initPkt(p); - if (log_flag == 1) { + 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; @@ -296,7 +289,8 @@ void UwAUVErrorSimpleModule::recv(Packet* p) { hdr_uwAUV_error* uwAUVh = hdr_uwAUV_error::access(p); - if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { //obsolete packets + //obsolete packets + if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { if (debug_) { std::cout << NOW << " UwAUVErrBModule::old error with sn " @@ -305,7 +299,8 @@ void UwAUVErrorSimpleModule::recv(Packet* p) { } else { //packet in order - if (alarm_mode && uwAUVh->x() == x_e && uwAUVh->y() == y_e){ //Valid pkt refering to my error + //Valid pkt refering to my error + if (alarm_mode && uwAUVh->x() == x_e && uwAUVh->y() == y_e){ if (uwAUVh->error() < 0 ){ @@ -317,15 +312,16 @@ void UwAUVErrorSimpleModule::recv(Packet* p) { sendTmr_.force_cancel(); sendTmr_.resched(period); - if (log_flag == 1) { + 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; + 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 ){ @@ -333,8 +329,8 @@ void UwAUVErrorSimpleModule::recv(Packet* p) { alarm_mode = true; if (debug_) - std::cout << NOW << " UwAUVErrBModule::recv(Packet *p) error ("<< x_e <<","<< y_e <<")" - "STOP until ctr arrival"<< std::endl; + std::cout << NOW << " UwAUVErrBModule::recv(Packet *p) error(" + << x_e <<","<< y_e <<") STOP until ctr arrival"<< std::endl; } } @@ -345,7 +341,7 @@ void UwAUVErrorSimpleModule::recv(Packet* p) { UwCbrModule::recv(p); - if (log_flag == 1) { + 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; diff --git a/DESERT_Addons/uwauv/uwauverror-simple-module.h b/DESERT_Addons/uwauv/uwauverror-simple-module.h index 69d8b46d..4e37d705 100644 --- a/DESERT_Addons/uwauv/uwauverror-simple-module.h +++ b/DESERT_Addons/uwauv/uwauverror-simple-module.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Regents of the SIGNET lab, University of Padova. +// 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 @@ -44,8 +44,6 @@ #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. */ - -using namespace std; class UwAUVErrorSimpleModule; @@ -170,7 +168,7 @@ class UwAUVErrorSimpleModule : public UwCbrModule { lower or equal than last_sn_confirmed.*/ - int log_flag; /**< Flag to enable log file writing.*/ + int log_on_file; /**< Flag to enable log file writing.*/ Packet* p; int period; std::ofstream out_file_stats; /**< Output stream for the textual file of debug */ diff --git a/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition.cpp b/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition.cpp index 7071be27..6386f1a3 100644 --- a/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition.cpp +++ b/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Regents of the SIGNET lab, University of Padova. +// 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 @@ -120,31 +120,29 @@ UWSMWPPosition::setDest( if (alarm_mode){ if (debug_) - printf("Alarm_mode %f, dest(%f,%f,%f) not accepted\n", - alarm_mode, - x_dest, - y_dest, - z_dest); + 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 (waypoints[0][0] == x_dest && waypoints[0][1] == y_dest && + waypoints[0][2] == z_dest){ if (debug_) - printf("New dest next waypoint in the queue (%f,%f,%f)\n", - waypoints[0][0], - waypoints[0][1], - waypoints[0][2]); + 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_) - printf("New destination (%f,%f,%f), skip the queue\n", - x_dest, - y_dest, - z_dest); + cout << "New destination (" << x_dest << "," << y_dest << + "," << z_dest << "), skip the queue"<< std::endl; + } @@ -154,29 +152,19 @@ UWSMWPPosition::setDest( } if (debug_) - printf("Pos (%f,%f,%f), last dest(%f,%f,%f), new dest = (%f,%f,%f)\n", - x_, - y_, - z_, - Xdest_, - Ydest_, - Zdest_, - x_dest, - y_dest, - z_dest); + 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_) - printf("Pos (%f,%f,%f), new dest(%f,%f,%f), speed = %f\n", - x_, - y_, - z_, - Xdest_, - Ydest_, - Zdest_, - speed_setted); + cout << "Pos (" << x_ << "," << y_ << "," << z_ << "), new dest(" + << Xdest_ << "," << Ydest_ << "," << Zdest_ << "), speed = " + << speed_setted << std::endl; + } } @@ -187,30 +175,27 @@ UWSMWPPosition::setDest(double x_dest, double y_dest, double z_dest) { if (alarm_mode){ if (debug_) - printf("Alarm_mode %f, dest(%f,%f,%f) not accepted\n", - alarm_mode, - x_dest, - y_dest, - z_dest); + 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 (waypoints[0][0] == x_dest && waypoints[0][1] == y_dest && + waypoints[0][2] == z_dest){ if (debug_) - printf("New dest next waypoint in the queue (%f,%f,%f)\n", - waypoints[0][0], - waypoints[0][1], - waypoints[0][2]); + 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_) - printf("New destionation (%f,%f,%f), skip the queue\n", - x_dest, - y_dest, - z_dest); + cout << "New destination (" << x_dest << "," << y_dest << "," + << z_dest << "), skip the queue" << std::endl; + } @@ -224,13 +209,9 @@ UWSMWPPosition::setDest(double x_dest, double y_dest, double z_dest) if (debug_) - printf("Pos (%f,%f,%f), new dest(%f,%f,%f)\n", - x_, - y_, - z_, - Xdest_, - Ydest_, - Zdest_); + cout << "Pos (" << x_ << "," << y_ << "," << z_ << "), new dest(" << + Xdest_ << "," << Ydest_ << "," << Zdest_ << ")"<< std::endl; + } } @@ -253,23 +234,18 @@ UWSMWPPosition::addDest( if (!exist){ waypoints.push_back({x_dest,y_dest,z_dest, speed_setted}); if (debug_) - printf("New waypoint (%f,%f,%f)\n", - x_dest, - y_dest, - z_dest); + cout << "New waypoint (" << x_dest << "," << y_dest << "," + << z_dest << ")\n"; + } }else{ UWSMWPPosition::setDest(x_dest,y_dest,z_dest, speed_setted); if (debug_) - printf("Pos (%f,%f,%f), new dest(%f,%f,%f)\n", - x_, - y_, - z_, - Xdest_, - Ydest_, - Zdest_); + cout << "Pos (" << x_ << "," << y_ << "," << z_ << "), new dest(" + << Xdest_ << "," << Ydest_ << "," << Zdest_ << ")\n"; + } } @@ -292,10 +268,9 @@ UWSMWPPosition::addDest( if (!exist){ waypoints.push_back({x_dest,y_dest,z_dest}); if (debug_) - printf("New waypoint (%f,%f,%f)\n", - x_dest, - y_dest, - z_dest); + cout << "New waypoint (" << x_dest << "," << y_dest << "," + << z_dest << ")\n"; + } @@ -304,13 +279,9 @@ UWSMWPPosition::addDest( UWSMWPPosition::setDest(x_dest,y_dest,z_dest); if (debug_) - printf("Pos (%f,%f,%f), new dest(%f,%f,%f)\n", - x_, - y_, - z_, - Xdest_, - Ydest_, - Zdest_); + cout << "Pos (" << x_ << "," << y_ << "," << z_ << "), new dest(" + << Xdest_ << "," << Ydest_ << "," << Zdest_ << ")\n"; + } } @@ -323,7 +294,7 @@ UWSMWPPosition::update(double now) double gamma; double theta; - double theta_den = sqrt(pow(Ydest_ - Ysorg_, 2.0) + //distance to destination + double theta_den = sqrt(pow(Ydest_ - Ysorg_, 2.0) + pow(Xdest_ - Xsorg_, 2.0) + pow(Zdest_ - Zsorg_, 2.0)); if (theta_den == 0) { @@ -335,29 +306,30 @@ UWSMWPPosition::update(double now) if (!waypoints.empty()){ - if(waypoints[0][0] == Xdest_ && waypoints[0][1] == Ydest_ && waypoints[0][2] == Zdest_){ + if(waypoints[0][0] == Xdest_ && waypoints[0][1] == Ydest_ + && waypoints[0][2] == Zdest_){ if (debug_) - printf("Last waypoints erased (%f,%f,%f)\n", - waypoints[0][0], - waypoints[0][1], - waypoints[0][2]); + 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]); + 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]); + UWSMWPPosition::setDest(waypoints[0][0],waypoints[0][1], + waypoints[0][2]); } if (debug_) - printf("New dest (%f,%f,%f) from waypoints list\n", - Xdest_, - Ydest_, - Zdest_); + cout << "New dest (" << Xdest_ << "," << Ydest_ << "," + << Zdest_ << ") from waypoints list\n"; + } } @@ -383,10 +355,13 @@ UWSMWPPosition::update(double now) y_ = Ysorg_ + (speed_ * (now - trgTime_)) * sin(theta) * sin(gamma); z_ = Zsorg_ + (speed_ * (now - trgTime_)) * cos(theta); - if (pow(Ydest_ - Ysorg_, 2.0) + pow(Xdest_ - Xsorg_, 2.0) + - pow(Zdest_ - Zsorg_, 2.0) < - pow(x_ - Xsorg_, 2.0) + pow(y_ - Ysorg_, 2.0) + - pow(z_ - Zsorg_, 2.0)) { + 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_; @@ -394,20 +369,19 @@ UWSMWPPosition::update(double now) if (debug_) - printf("Destination (%f,%f,%f) reached\n", - Xdest_, - Ydest_, - Zdest_); + cout << "Destination (" << Xdest_ << "," << Ydest_ << "," << + Zdest_ << ") reached\n"; + if (!waypoints.empty()){ - if(waypoints[0][0] == Xdest_ && waypoints[0][1] == Ydest_ && waypoints[0][2] == Zdest_){ + if(waypoints[0][0] == Xdest_ && waypoints[0][1] == Ydest_ && + waypoints[0][2] == Zdest_){ if (debug_) - printf("Last waypoints erased (%f,%f,%f)\n", - waypoints[0][0], - waypoints[0][1], - waypoints[0][2]); + cout << "Last waypoints erased (" << waypoints[0][0] << + "," << waypoints[0][1] << "," << waypoints[0][2] << + ")\n"; waypoints.erase(waypoints.begin()); @@ -415,22 +389,23 @@ UWSMWPPosition::update(double now) if (!waypoints.empty()){ if (debug_) - printf("Next dest (%f,%f,%f)\n", - waypoints[0][0], - waypoints[0][1], - waypoints[0][2]); + 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]); + 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]); + UWSMWPPosition::setDest(waypoints[0][0],waypoints[0][1], + waypoints[0][2]); } if (debug_) - printf("New dest (%f,%f,%f) from waypoints list\n", - Xdest_, - Ydest_, - Zdest_); + cout << "New dest (" << Xdest_ << "," << Ydest_ << "," << + Zdest_ << ") from waypoints list\n"; + } } @@ -438,19 +413,11 @@ UWSMWPPosition::update(double now) } if (debug_) - printf("New pos (%f,%f,%f), dest(%f,%f,%f), source(%f,%f,%f), speed %f sen(%f)=%f\n", - x_, - y_, - z_, - Xdest_, - Ydest_, - Zdest_, - Xsorg_, - Ysorg_, - Zsorg_, - speed_, - gamma, - sin(gamma)); + cout << "New pos (" << x_ << "," << y_ << "," << z_ << "), dest(" << Xdest_ << + "," << Ydest_ << "," << Zdest_ << "), source(" << Xsorg_ << "," << Ysorg_ << + "," << Zsorg_ << "), speed " << speed_ << " sen(" << gamma << ")=" << + sin(gamma) << "\n"; + } lastUpdateTime_ = now; diff --git a/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition.h b/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition.h index 9bde0031..f0a99c0a 100644 --- a/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition.h +++ b/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Regents of the SIGNET lab, University of Padova. +// 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 diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl index 2ab84eee..72a1316d 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl @@ -26,7 +26,7 @@ proc createASV { id } { 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_flag_ 1 + 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) diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv_basic.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv_basic.tcl index bd8f79cb..1d707511 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv_basic.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv_basic.tcl @@ -26,7 +26,7 @@ proc createASV { id } { 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_flag_ 1 + 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) diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl index 40d2ecf9..2c357b7d 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl @@ -21,7 +21,7 @@ proc createAUV { id } { 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_flag_ 1 + 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) diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv_basic.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv_basic.tcl index 9f4b8e3a..3476684a 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv_basic.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv_basic.tcl @@ -21,7 +21,7 @@ proc createAUV { id } { 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_flag_ 1 + 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) From 9c9786219d068d770642430249df19a82cad55e0 Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Sun, 22 Oct 2023 16:38:51 +0200 Subject: [PATCH 26/36] spaces to tab conversion --- DESERT_Addons/uwauv/uwauv-module.cc | 36 +++++++++---------- DESERT_Addons/uwauv/uwauvctrer-module.cc | 8 ++--- .../uwauv/uwauvctrer-simple-module.cc | 8 ++--- DESERT_Addons/uwauv/uwauverror-module.cc | 10 +++--- .../uwauv/uwauverror-simple-module.cc | 6 ++-- .../uwsmwpposition/uwsmwpposition.cpp | 2 +- 6 files changed, 35 insertions(+), 35 deletions(-) diff --git a/DESERT_Addons/uwauv/uwauv-module.cc b/DESERT_Addons/uwauv/uwauv-module.cc index 73f9766a..24cb0232 100644 --- a/DESERT_Addons/uwauv/uwauv-module.cc +++ b/DESERT_Addons/uwauv/uwauv-module.cc @@ -93,15 +93,15 @@ UwAUVModule::UwAUVModule() , 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; - } + 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; + } } @@ -119,15 +119,15 @@ UwAUVModule::UwAUVModule(UWSMWPPosition* p) , 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; - } + 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; + } } diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.cc b/DESERT_Addons/uwauv/uwauvctrer-module.cc index bf00808c..27645bc2 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.cc +++ b/DESERT_Addons/uwauv/uwauvctrer-module.cc @@ -82,8 +82,8 @@ UwAUVCtrErModule::UwAUVCtrErModule(UWSMWPPosition* 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("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 ); @@ -106,8 +106,8 @@ UwAUVCtrErModule::UwAUVCtrErModule() 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("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 ); diff --git a/DESERT_Addons/uwauv/uwauvctrer-simple-module.cc b/DESERT_Addons/uwauv/uwauvctrer-simple-module.cc index 88e92008..fce38d91 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-simple-module.cc +++ b/DESERT_Addons/uwauv/uwauvctrer-simple-module.cc @@ -79,8 +79,8 @@ UwAUVCtrErSimpleModule::UwAUVCtrErSimpleModule(UWSMWPPosition* 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("drop_old_waypoints_", (int*) &drop_old_waypoints); + bind("log_on_file_", (int*) &log_on_file ); bind("period_", (int*) &period ); } @@ -98,8 +98,8 @@ UwAUVCtrErSimpleModule::UwAUVCtrErSimpleModule() 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("drop_old_waypoints_", (int*) &drop_old_waypoints); + bind("log_on_file_", (int*) &log_on_file ); bind("period_", (int*) &period ); } diff --git a/DESERT_Addons/uwauv/uwauverror-module.cc b/DESERT_Addons/uwauv/uwauverror-module.cc index a52b0f32..90a5c473 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.cc +++ b/DESERT_Addons/uwauv/uwauverror-module.cc @@ -87,8 +87,8 @@ UwAUVErrorModule::UwAUVErrorModule() { posit= new UWSMWPPosition(); - bind("drop_old_waypoints_", (int*) &drop_old_waypoints); - bind("log_on_file_", (int*) &log_on_file ); + 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 ); @@ -109,8 +109,8 @@ UwAUVErrorModule::UwAUVErrorModule(UWSMWPPosition* p) , accuracy(0.001) { posit = p; - bind("drop_old_waypoints_", (int*) &drop_old_waypoints); - bind("log_on_file_", (int*) &log_on_file ); + 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 ); @@ -269,7 +269,7 @@ void UwAUVErrorModule::initPkt(Packet* p) { } else { - uwAUVh->x() = x_e; + uwAUVh->x() = x_e; uwAUVh->y() = y_e; uwAUVh->error() = error_m; this->p = p; diff --git a/DESERT_Addons/uwauv/uwauverror-simple-module.cc b/DESERT_Addons/uwauv/uwauverror-simple-module.cc index 5a090226..31a06a12 100644 --- a/DESERT_Addons/uwauv/uwauverror-simple-module.cc +++ b/DESERT_Addons/uwauv/uwauverror-simple-module.cc @@ -83,7 +83,7 @@ UwAUVErrorSimpleModule::UwAUVErrorSimpleModule() { posit= new UWSMWPPosition(); bind("drop_old_waypoints_", (int*) &drop_old_waypoints); - bind("log_on_file_", (int*) &log_on_file ); + bind("log_on_file_", (int*) &log_on_file ); bind("period_", (int*) &period ); bind("error_p_", (int*) &error_p ); bind("sigma_", (double*) &sigma); @@ -104,8 +104,8 @@ UwAUVErrorSimpleModule::UwAUVErrorSimpleModule(UWSMWPPosition* p) , accuracy(0.01) { posit = p; - bind("drop_old_waypoints_", (int*) &drop_old_waypoints); - bind("log_on_file_", (int*) &log_on_file ); + 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); diff --git a/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition.cpp b/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition.cpp index 6386f1a3..7dd60d89 100644 --- a/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition.cpp +++ b/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition.cpp @@ -185,7 +185,7 @@ UWSMWPPosition::setDest(double x_dest, double y_dest, double z_dest) waypoints[0][2] == z_dest){ if (debug_) - cout << "New dest next waypoint in the queue (" << waypoints[0][0] + cout << "New dest next waypoint in the queue (" << waypoints[0][0] << "," << waypoints[0][1] << "," << waypoints[0][2] << ")"<< std::endl; From 3df744cb9ef751228028afade81cc0c6b4c46b59 Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Mon, 23 Oct 2023 21:51:24 +0200 Subject: [PATCH 27/36] added rov immersion to the simulation --- DESERT_Addons/uwauv/uwauvctrer-module.cc | 192 +++++++++++++----- DESERT_Addons/uwauv/uwauvctrer-module.h | 10 +- .../desert_samples/AUV/test_uwauv_error.tcl | 9 +- 3 files changed, 151 insertions(+), 60 deletions(-) diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.cc b/DESERT_Addons/uwauv/uwauvctrer-module.cc index 27645bc2..8d0eebc9 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.cc +++ b/DESERT_Addons/uwauv/uwauvctrer-module.cc @@ -195,6 +195,16 @@ float UwAUVCtrErModule::getDistance(float x_s,float y_s,float x_d,float y_d){ } +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); @@ -217,33 +227,104 @@ void UwAUVCtrErModule::initPkt(Packet* p) { << "released"<< std::endl; - } else if (alarm_mode == 2){ //I need to go there + } 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)){ + if (getDistance(posit->getX(),posit->getY(),x_err,y_err) == 0.0){ found = true; - x_s = x_err; - y_s = y_err; + //x_s = x_err; + //y_s = y_err; + - if (debug_) + alarm_mode = 3; + posit->setDest(x_err,y_err,-990,speed); + + if (debug_){ std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p) SV" - << "reached the destination"<< std::endl; + << "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))){ + } else if(getDistance(x_sorg,y_sorg,x_err,y_err) < + getDistance(posit->getX(),posit->getY(),x_sorg,y_sorg)){ + found = true; + //x_s = x_err; + //y_s = y_err; + + alarm_mode = 3; + posit->setDest(x_err,y_err,-990,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){ + + 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(); + + } + + found = false; + + if (getDistance(posit->getX(),posit->getY(),posit->getZ(),x_err,y_err,-990) == 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,-990) < + 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 has gone" - << "too far "<< std::endl; - - } + std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p) SV" + << "in range (too far)"<< std::endl; + } + if (found){ uwAUVh->error() = -2; @@ -252,6 +333,10 @@ void UwAUVCtrErModule::initPkt(Packet* p) { 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) { @@ -261,35 +346,17 @@ void UwAUVCtrErModule::initPkt(Packet* p) { } - 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 << " UwAUVCtrErModule::initPkt(Packet *p) ERROR ("<< x_err << "," << y_err << ") SOLVED" << std::endl; } - } else { + x_err = -4000; + y_err = -4000; - 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; - } + } - } - } + } UwCbrModule::initPkt(p); @@ -315,6 +382,8 @@ void UwAUVCtrErModule::recv(Packet* p) { rcv_queue.push_back({uwAUVh->x(), uwAUVh->y()}); + + //dev_status status = checkError(uwAUVh->error(),1,uwAUVh->x(), uwAUVh->y()); int status = checkError(uwAUVh->error(),1,uwAUVh->x(), uwAUVh->y()); bool exists = false; @@ -385,8 +454,9 @@ void UwAUVCtrErModule::recv(Packet* p) { x_sorg = posit->getX(); y_sorg = posit->getY(); - posit->setDest(x_err,y_err,posit->getZ(),speed); + posit->addDest(x_err,y_err,-1,speed); alarm_mode = 2; + active_alarm = true; if (debug_) std::cout << NOW << " UwAUVCtrErrModule::recv(Packet *p) SV" @@ -421,8 +491,9 @@ void UwAUVCtrErModule::recv(Packet* p) { x_err = alarm_queue[0][0]; y_err = alarm_queue[0][1]; - posit->setDest(x_err,y_err,posit->getZ(),speed); + posit->addDest(x_err,y_err,-1,speed); alarm_mode = 2; + active_alarm = true; x_sorg = posit->getX(); y_sorg = posit->getY(); @@ -431,7 +502,7 @@ void UwAUVCtrErModule::recv(Packet* p) { } else { - alarm_mode = 3; + //alarm_mode = 4; //wait another app to take care of it } @@ -505,7 +576,6 @@ void UwAUVCtrErModule::recv(Packet* p) { } else { - //status 0 --> no error int i = 0; for (auto it = gray_queue.begin(); it != gray_queue.end(); ++it) { if ((*it)[0]== uwAUVh->x() && (*it)[1] == uwAUVh->y()) { @@ -514,20 +584,34 @@ void UwAUVCtrErModule::recv(Packet* p) { } } - error_released = true; - x_s = uwAUVh->x(); - y_s = uwAUVh->y(); + 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 (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(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; } - - if (debug_) - std::cout << NOW << " UwAUVCtrErrModule:: After some tx" - <<"converged to no error" << std::endl; + } } @@ -542,15 +626,19 @@ 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 = 0; + //status = no_error; + status=0; } else if (p_e > (1-accuracy)){ // FOR SURE ERROR + //status = error; status = 2; } else { //I NEED MORE DATA - status = 1; + //status = undetermined; + status=1; } return status; diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.h b/DESERT_Addons/uwauv/uwauvctrer-module.h index 34972a87..e03b904b 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.h +++ b/DESERT_Addons/uwauv/uwauvctrer-module.h @@ -157,7 +157,8 @@ class UwAUVCtrErModule : public UwCbrModule { */ static inline int getAUVErrorHeaderSize() { return sizeof(hdr_uwAUV_error); } - float getDistance(float x_s,float y_s, float x_d, float y_d); + float getDistance(float x_s,float y_s, float x_d, float y_d); + float getDistance(float x_s,float y_s, float z_s, float x_d, float y_d, float z_d); protected: @@ -180,6 +181,7 @@ class UwAUVCtrErModule : public UwCbrModule { double speed; static int alarm_mode; + bool active_alarm; bool error_released; /* * 0 no error * 1 maybe an error --> wait more info @@ -190,14 +192,15 @@ class UwAUVCtrErModule : public UwCbrModule { private: - - virtual int checkError(double m, int n_pkt, float x, float y); + enum dev_status {no_error = 0, undetermined = 1, error=2}; + 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; + vector> rcv_queue; @@ -208,4 +211,5 @@ int UwAUVCtrErModule::alarm_mode = 0; vector> UwAUVCtrErModule::alarm_queue = {}; vector> UwAUVCtrErModule::gray_queue = {}; + #endif // UWAUVCtr_MODULE_H 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 index 739554f8..fa98dc5f 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwauv_error.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwauv_error.tcl @@ -103,8 +103,6 @@ load libuwphy_clmsgs.so load libuwstats_utilities.so load libuwphysical.so load libuwposbasedrt.so -#load libuwnoderep.so; #non riesco ad importarla -#load libuwsecurity_clmsg.so; #non riesco ad importarla load libuwflooding.so load libuwinterference.so load libuwphy_clmsgs.so @@ -126,9 +124,9 @@ $ns use-Miracle ################## # Tcl variables # ################## -set opt(n_auv) 4 ;# Number of Nodes +set opt(n_auv) 4;#4 ;# Number of Nodes set opt(starttime) 1 -set opt(stoptime) 150000 +set opt(stoptime) 250000;#150000 set opt(txduration) [expr $opt(stoptime) - $opt(starttime)] set opt(rngstream) 1 @@ -151,7 +149,8 @@ set opt(txpower_op) 30 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 + # receveing area, it has to be the same for optical physical and propagation +set opt(rxArea) 0.0000011 ; set opt(c) 0.4 ; # coastal water set opt(theta) 1 set opt(id) [expr 1.0e-9] From 23623a4650c9fffacd06c9b941236f4e3919791b Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Mon, 23 Oct 2023 22:48:54 +0200 Subject: [PATCH 28/36] added rover immersion to the simulation --- .../uwauv/uwauvctrer-simple-module.cc | 151 +++++++++++++----- .../uwauv/uwauvctrer-simple-module.h | 3 + 2 files changed, 113 insertions(+), 41 deletions(-) diff --git a/DESERT_Addons/uwauv/uwauvctrer-simple-module.cc b/DESERT_Addons/uwauv/uwauvctrer-simple-module.cc index fce38d91..cde62150 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-simple-module.cc +++ b/DESERT_Addons/uwauv/uwauvctrer-simple-module.cc @@ -176,6 +176,15 @@ float UwAUVCtrErSimpleModule::getDistance(float x_s,float y_s,float x_d,float y_ } +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); @@ -184,43 +193,99 @@ void UwAUVCtrErSimpleModule::initPkt(Packet* p) { uwAUVh->error() = 0; - if (alarm_mode){ + if ((alarm_mode == 1) & active_alarm){ //If in the right position if ((getDistance(posit->getX(),posit->getY(),x_err,y_err) == 0.0)){ found = true; - x_s = x_err; - y_s = y_err; + alarm_mode = 2; + posit->setDest(x_err,y_err,-990,speed); + //x_s = x_err; + //y_s = y_err; - if (debug_) + if (debug_){ std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p)" - << "SV reached the destination"<< std::endl; - + << "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; - x_s = x_err; - y_s = y_err; - + alarm_mode = 2; + posit->setDest(x_err,y_err,-990,speed); + //x_s = x_err; + //y_s = y_err; - if (debug_) + 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,-990) == 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,-990) < + 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){ + if (found) { uwAUVh->error() = -1; - alarm_mode = false; + 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 (log_on_file == 1) { pos_log.open("log/position_log.csv",std::ios_base::app); @@ -240,8 +305,9 @@ void UwAUVCtrErSimpleModule::initPkt(Packet* p) { x_err = alarm_queue[0][0]; y_err = alarm_queue[0][1]; - posit->setDest(x_err,y_err,posit->getZ(),speed); - alarm_mode = true; + posit->addDest(x_err,y_err,-1,speed); + alarm_mode = 1; + active_alarm = true; alarm_queue.erase(alarm_queue.begin()); @@ -254,23 +320,7 @@ void UwAUVCtrErSimpleModule::initPkt(Packet* p) { << "Y = " << y_err<< std::endl; } } - - } else { - - 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 (log_on_file == 1) { @@ -310,6 +360,8 @@ void UwAUVCtrErSimpleModule::recv(Packet* p) { if (!alarm_mode){ + rcv_queue.push_back({uwAUVh->x(), uwAUVh->y()}); + //check in the queue before if (alarm_queue.empty()){ @@ -318,9 +370,10 @@ void UwAUVCtrErSimpleModule::recv(Packet* p) { x_sorg = posit->getX(); y_sorg = posit->getY(); - posit->setDest(x_err,y_err,posit->getZ(),speed); + posit->addDest(x_err,y_err,-1,speed); - alarm_mode = true; + alarm_mode = 1; + active_alarm = true; if (debug_) std::cout << NOW << " UwAUVCtrErrModule::recv(Packet *p)" @@ -339,14 +392,32 @@ void UwAUVCtrErSimpleModule::recv(Packet* p) { } else { - x_err = alarm_queue[0][0]; - y_err = alarm_queue[0][1]; - posit->setDest(x_err,y_err,posit->getZ(),speed); + exist=false; - alarm_mode = true; - - x_sorg = posit->getX(); - y_sorg = posit->getY(); + 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()); + } else { + //wait another app to take care of it + } exist = false; @@ -360,8 +431,6 @@ void UwAUVCtrErSimpleModule::recv(Packet* p) { if (!exist){ alarm_queue.push_back({uwAUVh->x(),uwAUVh->y()}); } - - alarm_queue.erase(alarm_queue.begin()); if (log_on_file == 1) { diff --git a/DESERT_Addons/uwauv/uwauvctrer-simple-module.h b/DESERT_Addons/uwauv/uwauvctrer-simple-module.h index 65ce1a8c..cc5077b0 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-simple-module.h +++ b/DESERT_Addons/uwauv/uwauvctrer-simple-module.h @@ -159,6 +159,7 @@ class UwAUVCtrErSimpleModule : public UwCbrModule { static inline int getAUVErrorHeaderSize() { return sizeof(hdr_uwAUV_error); } float getDistance(float x_s,float y_s, float x_d, float y_d); + float getDistance(float x_s,float y_s, float z_s, float x_d, float y_d, float z_d); @@ -181,6 +182,7 @@ class UwAUVCtrErSimpleModule : public UwCbrModule { float x_sorg; float y_sorg; double speed; + bool active_alarm; static int alarm_mode; static vector> alarm_queue; @@ -190,6 +192,7 @@ class UwAUVCtrErSimpleModule : public UwCbrModule { std::ofstream pos_log; std::ofstream err_log; std::ofstream t_err_log; + vector> rcv_queue; }; From c75744390ab9cb421404a3cd6271aaa920a15400 Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Tue, 24 Oct 2023 17:05:21 +0200 Subject: [PATCH 29/36] postion log correction --- DESERT_Addons/uwauv/uwauvctrer-module.cc | 17 +++------ .../uwauv/uwauvctrer-simple-module.cc | 36 +++++++------------ 2 files changed, 17 insertions(+), 36 deletions(-) diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.cc b/DESERT_Addons/uwauv/uwauvctrer-module.cc index 8d0eebc9..f28f169d 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.cc +++ b/DESERT_Addons/uwauv/uwauvctrer-module.cc @@ -246,7 +246,7 @@ void UwAUVCtrErModule::initPkt(Packet* p) { alarm_mode = 3; - posit->setDest(x_err,y_err,-990,speed); + posit->setDest(x_err,y_err,-90,speed); if (debug_){ std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p) SV" @@ -265,7 +265,7 @@ void UwAUVCtrErModule::initPkt(Packet* p) { //y_s = y_err; alarm_mode = 3; - posit->setDest(x_err,y_err,-990,speed); + posit->setDest(x_err,y_err,-90,speed); if (debug_){ @@ -291,19 +291,10 @@ void UwAUVCtrErModule::initPkt(Packet* p) { } if(alarm_mode == 3 && 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(); - - } found = false; - if (getDistance(posit->getX(),posit->getY(),posit->getZ(),x_err,y_err,-990) == 0.0){ + 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; @@ -312,7 +303,7 @@ void UwAUVCtrErModule::initPkt(Packet* p) { std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p) SV" << "in range"<< std::endl; - }else if(getDistance(x_sorg,y_sorg,-1,x_err,y_err,-990) < + }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; diff --git a/DESERT_Addons/uwauv/uwauvctrer-simple-module.cc b/DESERT_Addons/uwauv/uwauvctrer-simple-module.cc index cde62150..2a9cd33b 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-simple-module.cc +++ b/DESERT_Addons/uwauv/uwauvctrer-simple-module.cc @@ -195,12 +195,21 @@ void UwAUVCtrErSimpleModule::initPkt(Packet* p) { 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,-990,speed); + posit->setDest(x_err,y_err,-90,speed); //x_s = x_err; //y_s = y_err; @@ -217,7 +226,7 @@ void UwAUVCtrErSimpleModule::initPkt(Packet* p) { found = true; alarm_mode = 2; - posit->setDest(x_err,y_err,-990,speed); + posit->setDest(x_err,y_err,-90,speed); //x_s = x_err; //y_s = y_err; @@ -250,7 +259,7 @@ void UwAUVCtrErSimpleModule::initPkt(Packet* p) { found =false; - if ((getDistance(posit->getX(),posit->getY(),posit->getZ(),x_err,y_err,-990) == 0.0)){ + if ((getDistance(posit->getX(),posit->getY(),posit->getZ(),x_err,y_err,-90) == 0.0)){ found = true; x_s = x_err; @@ -261,7 +270,7 @@ void UwAUVCtrErSimpleModule::initPkt(Packet* p) { << "in range"<< std::endl; } - } else if((getDistance(x_sorg,y_sorg,-1,x_err,y_err,-990) < + } 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; @@ -286,15 +295,6 @@ void UwAUVCtrErSimpleModule::initPkt(Packet* p) { posit->setDest(x_err,y_err,-1,speed); - 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 << " UwAUVCtrErSimpleModule::initPkt(Packet *p)" << "ERROR ("<< x_err << "," << y_err << ") SOLVED" << std::endl; @@ -323,16 +323,6 @@ void UwAUVCtrErSimpleModule::initPkt(Packet* p) { } } - 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(); - - } - - UwCbrModule::initPkt(p); } From 5ef0a6c4489277005f02d5d96866f9d2dce05646 Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Tue, 24 Oct 2023 17:05:49 +0200 Subject: [PATCH 30/36] range ctr correction --- .../DESERT/samples/desert_samples/AUV/asv.tcl | 5 ++ .../samples/desert_samples/AUV/asv_basic.tcl | 1 + .../DESERT/samples/desert_samples/AUV/auv.tcl | 8 ++- .../samples/desert_samples/AUV/auv_basic.tcl | 7 +- .../desert_samples/AUV/test_uwauv_error.tcl | 67 ++++++++++--------- .../AUV/test_uwauv_error_basic.tcl | 16 ++--- 6 files changed, 58 insertions(+), 46 deletions(-) diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl index 72a1316d..9900a6a1 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl @@ -41,6 +41,9 @@ proc createASV { id } { 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] @@ -54,7 +57,9 @@ proc createASV { id } { 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} { diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv_basic.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv_basic.tcl index 1d707511..06495440 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv_basic.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv_basic.tcl @@ -40,6 +40,7 @@ proc createASV { id } { 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] diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl index 2c357b7d..b08d5eb0 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl @@ -2,7 +2,7 @@ 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 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 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 @@ -34,6 +34,8 @@ proc createAUV { id } { 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] @@ -52,6 +54,8 @@ proc createAUV { id } { 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] @@ -91,7 +95,7 @@ proc createAUV { id } { $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 $phy_op_auv($id) 0 + $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) ] diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv_basic.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv_basic.tcl index 3476684a..16f83764 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv_basic.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv_basic.tcl @@ -2,7 +2,7 @@ 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 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 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 @@ -51,8 +51,9 @@ proc createAUV { id } { 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/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" @@ -91,7 +92,7 @@ proc createAUV { id } { $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 $phy_op_auv($id) 0 + $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) ] 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 index fa98dc5f..feb551f8 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwauv_error.tcl +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwauv_error.tcl @@ -124,44 +124,45 @@ $ns use-Miracle ################## # Tcl variables # ################## -set opt(n_auv) 4;#4 ;# Number of Nodes -set opt(starttime) 1 -set opt(stoptime) 250000;#150000 -set opt(txduration) [expr $opt(stoptime) - $opt(starttime)] +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(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(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) 30 -set opt(acq_db_op) 10 -set opt(temperatura) 293.15 ; # in Kelvin -set opt(txArea) 0.000010 +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 ; # 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(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 @@ -226,7 +227,7 @@ 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/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 @@ -345,13 +346,13 @@ $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 +$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_ -1000 + $position_auv($id) setZ_ -100 $auv_app($id) setPosition $position_auv($id) $auv_err($id) setPosition $position_auv($id) 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 index e9239ace..e330bf49 100644 --- 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 @@ -1,5 +1,5 @@ # -# Copyright (c) 2015 Regents of the SIGNET lab, University of Padova. +# 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 @@ -123,11 +123,11 @@ $ns use-Miracle ################## # Tcl variables # ################## -set opt(n_auv) 4 ;# Number of Nodes +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(rngstream) 3 set opt(maxinterval_) 20.0 set opt(freq) 20000.0 @@ -138,15 +138,15 @@ 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(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) 30 +set opt(txpower_op) 50 set opt(acq_db_op) 10 set opt(temperatura) 293.15 ; # in Kelvin set opt(txArea) 0.000010 @@ -347,7 +347,7 @@ $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_ -1000 + $position_auv($id) setZ_ -100 $auv_app($id) setPosition $position_auv($id) $auv_err($id) setPosition $position_auv($id) From aaabfd8611a3f950a9d3ddae8f4571541554ed34 Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Tue, 26 Mar 2024 12:59:32 +0100 Subject: [PATCH 31/36] dyoxigen corrections --- DESERT_Addons/uwauv/m4/Makefile.am | 30 +++++++++ DESERT_Addons/uwauv/uwauv-module.h | 8 +-- DESERT_Addons/uwauv/uwauv-packet.h | 14 ++-- DESERT_Addons/uwauv/uwauvctr-module.cc | 2 +- DESERT_Addons/uwauv/uwauvctr-module.h | 4 +- DESERT_Addons/uwauv/uwauvctrer-module.cc | 17 +---- DESERT_Addons/uwauv/uwauvctrer-module.h | 67 +++++++++++++------ .../uwauv/uwauvctrer-simple-module.cc | 10 +-- .../uwauv/uwauvctrer-simple-module.h | 43 +++++++++--- DESERT_Addons/uwauv/uwauverror-module.h | 47 ++++++++----- .../uwauv/uwauverror-simple-module.cc | 6 +- .../uwauv/uwauverror-simple-module.h | 18 ++--- .../mobility/uwsmwpposition/uwsmwpposition.h | 22 +++++- 13 files changed, 195 insertions(+), 93 deletions(-) create mode 100755 DESERT_Addons/uwauv/m4/Makefile.am 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/uwauv-module.h b/DESERT_Addons/uwauv/uwauv-module.h index 2aa308c3..69e76a7b 100644 --- a/DESERT_Addons/uwauv/uwauv-module.h +++ b/DESERT_Addons/uwauv/uwauv-module.h @@ -160,10 +160,10 @@ class UwAUVModule : public UwCbrModule { 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_; /**hdr_uwAUV_monitoring describes UWAUV_monitoring packets sent by the AUV to the base station for monitoring the AUV state. + * 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. + 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. */ @@ -126,14 +128,16 @@ typedef struct hdr_uwAUV_monitoring { } hdr_uwAUV_monitoring; /** - * hdr_uwAUV_error describes UWAUV_error packets sent by the AUV to the surface vehicle to signal a problem. + * 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 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_; diff --git a/DESERT_Addons/uwauv/uwauvctr-module.cc b/DESERT_Addons/uwauv/uwauvctr-module.cc index 2d6e1f62..765fd949 100644 --- a/DESERT_Addons/uwauv/uwauvctr-module.cc +++ b/DESERT_Addons/uwauv/uwauvctr-module.cc @@ -45,7 +45,7 @@ extern packet_t PT_UWAUV; extern packet_t PT_UWAUV_CTR; /** -* Adds the module for UwAUVModuleClass in ns2. +* Adds the module for UwAUVCtrModuleClass in ns2. */ /** diff --git a/DESERT_Addons/uwauv/uwauvctr-module.h b/DESERT_Addons/uwauv/uwauvctr-module.h index 95672caf..adcf8d6f 100644 --- a/DESERT_Addons/uwauv/uwauvctr-module.h +++ b/DESERT_Addons/uwauv/uwauvctr-module.h @@ -137,7 +137,7 @@ class UwAUVCtrModule : public UwCbrModule { * * @param Packet* Pointer to the packet will be received. */ - virtual void recv(Packet*); + virtual void recv(Packet* p); /** * Creates and transmits a packet. @@ -177,7 +177,7 @@ class UwAUVCtrModule : public UwCbrModule { 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.*/ + 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.*/ diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.cc b/DESERT_Addons/uwauv/uwauvctrer-module.cc index f28f169d..d384ffee 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.cc +++ b/DESERT_Addons/uwauv/uwauvctrer-module.cc @@ -240,11 +240,8 @@ void UwAUVCtrErModule::initPkt(Packet* p) { //If in the right position if (getDistance(posit->getX(),posit->getY(),x_err,y_err) == 0.0){ - found = true; - //x_s = x_err; - //y_s = y_err; - + found = true; alarm_mode = 3; posit->setDest(x_err,y_err,-90,speed); @@ -261,9 +258,6 @@ void UwAUVCtrErModule::initPkt(Packet* p) { getDistance(posit->getX(),posit->getY(),x_sorg,y_sorg)){ found = true; - //x_s = x_err; - //y_s = y_err; - alarm_mode = 3; posit->setDest(x_err,y_err,-90,speed); @@ -373,8 +367,6 @@ void UwAUVCtrErModule::recv(Packet* p) { rcv_queue.push_back({uwAUVh->x(), uwAUVh->y()}); - - //dev_status status = checkError(uwAUVh->error(),1,uwAUVh->x(), uwAUVh->y()); int status = checkError(uwAUVh->error(),1,uwAUVh->x(), uwAUVh->y()); bool exists = false; @@ -491,12 +483,7 @@ void UwAUVCtrErModule::recv(Packet* p) { alarm_queue.erase(alarm_queue.begin()); - } else { - - //alarm_mode = 4; - //wait another app to take care of it - } - + }// otherwise wait another app to take care of it exists = false; for (const auto& vec : alarm_queue) { diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.h b/DESERT_Addons/uwauv/uwauvctrer-module.h index e03b904b..b0c5070d 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.h +++ b/DESERT_Addons/uwauv/uwauvctrer-module.h @@ -134,7 +134,7 @@ class UwAUVCtrErModule : public UwCbrModule { * * @param Packet* Pointer to the packet will be received. */ - virtual void recv(Packet*); + virtual void recv(Packet* p); /** * Returns the size in byte of a hdr_uwAUV_monitoring packet header. @@ -157,15 +157,36 @@ class UwAUVCtrErModule : public UwCbrModule { */ 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; + 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.*/ @@ -174,36 +195,44 @@ class UwAUVCtrErModule : public UwCbrModule { 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; + Packet* p; /**< Pointer to the packet that will be received*/ int log_on_file; - float x_sorg; - float y_sorg; - double speed; + 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; + 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; /* + bool error_released; /**< * 0 no error * 1 maybe an error --> wait more info * 2 for sure an error -> go there */ - static vector> alarm_queue; - static vector> gray_queue; + 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}; + 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; - - - vector> rcv_queue; - + 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*/ }; diff --git a/DESERT_Addons/uwauv/uwauvctrer-simple-module.cc b/DESERT_Addons/uwauv/uwauvctrer-simple-module.cc index 2a9cd33b..221c296b 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-simple-module.cc +++ b/DESERT_Addons/uwauv/uwauvctrer-simple-module.cc @@ -210,8 +210,6 @@ void UwAUVCtrErSimpleModule::initPkt(Packet* p) { found = true; alarm_mode = 2; posit->setDest(x_err,y_err,-90,speed); - //x_s = x_err; - //y_s = y_err; if (debug_){ std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p)" @@ -227,8 +225,6 @@ void UwAUVCtrErSimpleModule::initPkt(Packet* p) { found = true; alarm_mode = 2; posit->setDest(x_err,y_err,-90,speed); - //x_s = x_err; - //y_s = y_err; if (debug_){ std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p) SV" @@ -405,9 +401,7 @@ void UwAUVCtrErSimpleModule::recv(Packet* p) { y_sorg = posit->getY(); alarm_queue.erase(alarm_queue.begin()); - } else { - //wait another app to take care of it - } + } // otherwise wait another app to take care of it exist = false; @@ -445,7 +439,7 @@ void UwAUVCtrErSimpleModule::recv(Packet* p) { exist = false; for (const auto& vec : alarm_queue) { - // Controlla se le coordinate corrispondono + // Check if the coordinates are the same if (vec[0] == uwAUVh->x() && vec[1] == uwAUVh->y()) { exist = true; break; diff --git a/DESERT_Addons/uwauv/uwauvctrer-simple-module.h b/DESERT_Addons/uwauv/uwauvctrer-simple-module.h index cc5077b0..9183f978 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-simple-module.h +++ b/DESERT_Addons/uwauv/uwauvctrer-simple-module.h @@ -158,7 +158,28 @@ class UwAUVCtrErSimpleModule : public UwCbrModule { */ 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); @@ -167,8 +188,9 @@ class UwAUVCtrErSimpleModule : public UwCbrModule { 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; + 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.*/ @@ -177,22 +199,25 @@ class UwAUVCtrErSimpleModule : public UwCbrModule { 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; + Packet* p; /**< Pointer to the packet that will be received*/ int log_on_file; - float x_sorg; - float y_sorg; - double speed; + 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; - static vector> alarm_queue; + 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; + vector> rcv_queue; /**< list of error received*/ }; diff --git a/DESERT_Addons/uwauv/uwauverror-module.h b/DESERT_Addons/uwauv/uwauverror-module.h index c32d9808..598f0bb2 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.h +++ b/DESERT_Addons/uwauv/uwauverror-module.h @@ -48,13 +48,13 @@ class UwAUVErrorModule; /** -* UwSendTimer class is used to handle the scheduling period of UWAUV packets. +* UwAUVErrorSendTimer class is used to handle the scheduling period of UWAUV packets. */ class UwAUVErrorSendTimer : public UwSendTimer { public: /** - * Conscructor of UwSendTimer class + * Conscructor of UwAUVErrorSendTimer class * @param UwAUVCtrModule *m pointer to an object of type UwAUVCtrModule */ UwAUVErrorSendTimer(UwAUVErrorModule *m) : UwSendTimer((UwCbrModule*)(m)){ @@ -62,25 +62,25 @@ class UwAUVErrorSendTimer : public UwSendTimer { }; /** -* UwAUVModule class is used to manage UWAUV packets and to collect statistics about them. +* UwAUVErrorModule class is used to manage UWAUV packets and to collect statistics about them. */ class UwAUVErrorModule : public UwCbrModule { public: /** - * Default Constructor of UwAUVModule class. + * Default Constructor of UwAUVErrorModule class. */ UwAUVErrorModule(); /** - * Constructor with position setting of UwAUVModule class. + * Constructor with position setting of UwAUVErrorModule class. * * @param UWSMWPPosition* p Pointer to the AUV position */ UwAUVErrorModule(UWSMWPPosition* p); /** - * Destructor of UwAUVModule class. + * Destructor of UwAUVErrorModule class. */ virtual ~UwAUVErrorModule(); @@ -106,7 +106,7 @@ class UwAUVErrorModule : public UwCbrModule { * * @param Packet* Pointer to the packet will be received. */ - virtual void recv(Packet*); + virtual void recv(Packet* p); /** * Reset retransmissions @@ -167,25 +167,38 @@ class UwAUVErrorModule : public UwCbrModule { int log_on_file; /**< Flag to enable log file writing.*/ - Packet* p; + 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; - float y_e; - float error_m; - int alarm_mode; + 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; + 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; + 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*/ }; diff --git a/DESERT_Addons/uwauv/uwauverror-simple-module.cc b/DESERT_Addons/uwauv/uwauverror-simple-module.cc index 31a06a12..1e9d279b 100644 --- a/DESERT_Addons/uwauv/uwauverror-simple-module.cc +++ b/DESERT_Addons/uwauv/uwauverror-simple-module.cc @@ -59,9 +59,9 @@ static class UwAUVErrorSimpleModuleClass : public TclClass { } /** - * Creates the TCL object needed for the tcl language interpretation - * @return Pointer to an TclObject - */ + * Creates the TCL object needed for the tcl language interpretation + * @return Pointer to an TclObject + */ TclObject* create(int, const char*const*) { return (new UwAUVErrorSimpleModule()); } diff --git a/DESERT_Addons/uwauv/uwauverror-simple-module.h b/DESERT_Addons/uwauv/uwauverror-simple-module.h index 4e37d705..712709db 100644 --- a/DESERT_Addons/uwauv/uwauverror-simple-module.h +++ b/DESERT_Addons/uwauv/uwauverror-simple-module.h @@ -106,7 +106,7 @@ class UwAUVErrorSimpleModule : public UwCbrModule { * * @param Packet* Pointer to the packet will be received. */ - virtual void recv(Packet*); + virtual void recv(Packet* p); /** * Reset retransmissions @@ -169,21 +169,21 @@ class UwAUVErrorSimpleModule : public UwCbrModule { int log_on_file; /**< Flag to enable log file writing.*/ - Packet* p; + 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; - float y_e; - int alarm_mode; + 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; - double error_p; - double sigma; - double accuracy; + 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*/ }; diff --git a/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition.h b/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition.h index f0a99c0a..ead3e8e9 100644 --- a/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition.h +++ b/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition.h @@ -81,7 +81,27 @@ class UWSMWPPosition : public UWSMPosition * 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 * * From 91f02b20caa218384973f2d8b2223544232e9bdb Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Fri, 29 Mar 2024 15:38:27 +0100 Subject: [PATCH 32/36] indentation correction --- DESERT_Addons/uwauv/uwauverror-module.cc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/DESERT_Addons/uwauv/uwauverror-module.cc b/DESERT_Addons/uwauv/uwauverror-module.cc index 90a5c473..8edd64b7 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.cc +++ b/DESERT_Addons/uwauv/uwauverror-module.cc @@ -300,7 +300,7 @@ void UwAUVErrorModule::recv(Packet* p) { << uwAUVh->sn() << " dropped " << std::endl; } - } else { //packet in order + } else { //packet in order /** * error > 0 tx more data @@ -401,7 +401,7 @@ void UwAUVErrorModule::recv(Packet* p) { } } - last_sn_confirmed = uwAUVh->sn(); + last_sn_confirmed = uwAUVh->sn(); } UwCbrModule::recv(p); @@ -418,21 +418,21 @@ void UwAUVErrorModule::recv(Packet* p) { double UwAUVErrorModule::getErrorMeasure(){ std::random_device rd; - std::mt19937 gen(rd()); - std::uniform_real_distribution<> u_dis(0.0, 1.0); + 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); + // 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); + // 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; + 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; @@ -465,11 +465,11 @@ double UwAUVErrorModule::getErrorMeasure(){ double UwAUVErrorModule::getErrorMeasure(double t_e){ std::random_device rd; - std::mt19937 gen(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); + // Generate a random value from the Gaussian distribution + double noise = n_dis(gen); double m = t_e + noise; From 8b8122e87a9f1f93709e5bbe67a5a24d24f62472 Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Sat, 30 Mar 2024 10:04:18 +0100 Subject: [PATCH 33/36] blank to tab --- DESERT_Addons/uwauv/uwauv-module.cc | 10 ++++---- DESERT_Addons/uwauv/uwauv-module.h | 24 +++++++++---------- DESERT_Addons/uwauv/uwauvctr-module.h | 14 +++++------ DESERT_Addons/uwauv/uwauvctrer-module.cc | 2 +- DESERT_Addons/uwauv/uwauvctrer-module.h | 8 +++---- .../uwauv/uwauvctrer-simple-module.h | 8 +++---- DESERT_Addons/uwauv/uwauverror-module.cc | 2 +- .../uwauv/uwauverror-simple-module.cc | 9 ++++--- .../uwauv/uwauverror-simple-module.h | 2 +- 9 files changed, 39 insertions(+), 40 deletions(-) diff --git a/DESERT_Addons/uwauv/uwauv-module.cc b/DESERT_Addons/uwauv/uwauv-module.cc index 24cb0232..ab1b4d4c 100644 --- a/DESERT_Addons/uwauv/uwauv-module.cc +++ b/DESERT_Addons/uwauv/uwauv-module.cc @@ -61,15 +61,15 @@ static class UwAUVModuleClass : public TclClass { public: /** - * Constructor of the class - */ + * Constructor of the class + */ UwAUVModuleClass() : TclClass("Module/UW/AUV") { } /** - * Creates the TCL object needed for the tcl language interpretation - * @return Pointer to an TclObject - */ + * Creates the TCL object needed for the tcl language interpretation + * @return Pointer to an TclObject + */ TclObject* create(int, const char*const*) { return (new UwAUVModule()); } diff --git a/DESERT_Addons/uwauv/uwauv-module.h b/DESERT_Addons/uwauv/uwauv-module.h index 69e76a7b..2398a259 100644 --- a/DESERT_Addons/uwauv/uwauv-module.h +++ b/DESERT_Addons/uwauv/uwauv-module.h @@ -87,20 +87,20 @@ class UwAUVModule : public UwCbrModule { 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. - * - **/ + * 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. - */ + * 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) ; /** @@ -122,7 +122,7 @@ class UwAUVModule : public UwCbrModule { * * @return the current AUV position */ - inline UWSMWPPosition* getPosition() const { return posit; } + inline UWSMWPPosition* getPosition() const { return posit; } /** * Returns the size in byte of a hdr_uwAUV_monitoring packet header. diff --git a/DESERT_Addons/uwauv/uwauvctr-module.h b/DESERT_Addons/uwauv/uwauvctr-module.h index adcf8d6f..e92ea393 100644 --- a/DESERT_Addons/uwauv/uwauvctr-module.h +++ b/DESERT_Addons/uwauv/uwauvctr-module.h @@ -55,9 +55,9 @@ class UwAUVCtrSendTimer : public UwSendTimer { public: /** - * Conscructor of UwSendTimer class - * @param UwAUVCtrModule *m pointer to an object of type UwAUVCtrModule - */ + * Conscructor of UwSendTimer class + * @param UwAUVCtrModule *m pointer to an object of type UwAUVCtrModule + */ UwAUVCtrSendTimer(UwAUVCtrModule *m) : UwSendTimer((UwCbrModule*)(m)){ }; }; @@ -94,10 +94,10 @@ class UwAUVCtrModule : public UwCbrModule { 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. - */ + * 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) ; /** diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.cc b/DESERT_Addons/uwauv/uwauvctrer-module.cc index d384ffee..4975cdfa 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.cc +++ b/DESERT_Addons/uwauv/uwauvctrer-module.cc @@ -603,7 +603,7 @@ void UwAUVCtrErModule::recv(Packet* 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; + 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 diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.h b/DESERT_Addons/uwauv/uwauvctrer-module.h index b0c5070d..6998c72e 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.h +++ b/DESERT_Addons/uwauv/uwauvctrer-module.h @@ -96,10 +96,10 @@ class UwAUVCtrErModule : public UwCbrModule { 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. - */ + * 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) ; /** diff --git a/DESERT_Addons/uwauv/uwauvctrer-simple-module.h b/DESERT_Addons/uwauv/uwauvctrer-simple-module.h index 9183f978..7a0903e4 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-simple-module.h +++ b/DESERT_Addons/uwauv/uwauvctrer-simple-module.h @@ -96,10 +96,10 @@ class UwAUVCtrErSimpleModule : public UwCbrModule { 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. - */ + * 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) ; /** diff --git a/DESERT_Addons/uwauv/uwauverror-module.cc b/DESERT_Addons/uwauv/uwauverror-module.cc index 8edd64b7..e7d3cde0 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.cc +++ b/DESERT_Addons/uwauv/uwauverror-module.cc @@ -244,7 +244,7 @@ void UwAUVErrorModule::initPkt(Packet* p) { posit->setDest(posit->getXdest(),posit->getYdest(),posit->getZdest(),0); posit->setAlarm(true); - uwAUVh->x() = x_e; + uwAUVh->x() = x_e; uwAUVh->y() = y_e; uwAUVh->error() = error_m; this->p = p; diff --git a/DESERT_Addons/uwauv/uwauverror-simple-module.cc b/DESERT_Addons/uwauv/uwauverror-simple-module.cc index 1e9d279b..ca6c9ea9 100644 --- a/DESERT_Addons/uwauv/uwauverror-simple-module.cc +++ b/DESERT_Addons/uwauv/uwauverror-simple-module.cc @@ -59,9 +59,9 @@ static class UwAUVErrorSimpleModuleClass : public TclClass { } /** - * Creates the TCL object needed for the tcl language interpretation - * @return Pointer to an TclObject - */ + * Creates the TCL object needed for the tcl language interpretation + * @return Pointer to an TclObject + */ TclObject* create(int, const char*const*) { return (new UwAUVErrorSimpleModule()); } @@ -266,7 +266,7 @@ void UwAUVErrorSimpleModule::initPkt(Packet* p) { } else { - uwAUVh->x() = x_e; + uwAUVh->x() = x_e; uwAUVh->y() = y_e; uwAUVh->error() = 1; this->p = p; @@ -296,7 +296,6 @@ void UwAUVErrorSimpleModule::recv(Packet* p) { std::cout << NOW << " UwAUVErrBModule::old error with sn " << uwAUVh->sn() << " dropped " << std::endl; } - } else { //packet in order //Valid pkt refering to my error diff --git a/DESERT_Addons/uwauv/uwauverror-simple-module.h b/DESERT_Addons/uwauv/uwauverror-simple-module.h index 712709db..e893b70b 100644 --- a/DESERT_Addons/uwauv/uwauverror-simple-module.h +++ b/DESERT_Addons/uwauv/uwauverror-simple-module.h @@ -133,7 +133,7 @@ class UwAUVErrorSimpleModule : public UwCbrModule { * * @return the current AUV position */ - inline UWSMWPPosition* getPosition() const { return posit; } + inline UWSMWPPosition* getPosition() const { return posit; } /** * Returns the size in byte of a hdr_uwAUV_monitoring packet header. From 645162b4087e760b5ac29e9902ce571e0af9ade6 Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Sat, 30 Mar 2024 10:06:17 +0100 Subject: [PATCH 34/36] blank to tab --- DESERT_Addons/uwauv/uwauvctr-module.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/DESERT_Addons/uwauv/uwauvctr-module.cc b/DESERT_Addons/uwauv/uwauvctr-module.cc index 765fd949..c411d00c 100644 --- a/DESERT_Addons/uwauv/uwauvctr-module.cc +++ b/DESERT_Addons/uwauv/uwauvctr-module.cc @@ -55,15 +55,15 @@ static class UwAUVCtrModuleClass : public TclClass { public: /** - * Constructor of the class - */ + * 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 - */ + * Creates the TCL object needed for the tcl language interpretation + * @return Pointer to an TclObject + */ TclObject* create(int, const char*const*) { return (new UwAUVCtrModule()); } From ed5df9e7f119c50185839f407d8b0a5472061fb0 Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Sat, 30 Mar 2024 10:08:11 +0100 Subject: [PATCH 35/36] blank to tab --- DESERT_Addons/uwauv/uwauvctrer-module.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.cc b/DESERT_Addons/uwauv/uwauvctrer-module.cc index 4975cdfa..e2c3870f 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.cc +++ b/DESERT_Addons/uwauv/uwauvctrer-module.cc @@ -53,15 +53,15 @@ static class UwAUVCtrErModuleClass : public TclClass { public: /** - * Constructor of the class - */ + * 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 - */ + * Creates the TCL object needed for the tcl language interpretation + * @return Pointer to an TclObject + */ TclObject* create(int, const char*const*) { return (new UwAUVCtrErModule()); } From a0cb4a464b1f4ee52d9d845c8a9367f8d46849c3 Mon Sep 17 00:00:00 2001 From: Alessia Ortile Date: Sat, 30 Mar 2024 10:19:48 +0100 Subject: [PATCH 36/36] blanks to tab --- DESERT_Addons/uwauv/uwauvctrer-module.h | 6 ++-- .../uwauv/uwauvctrer-simple-module.cc | 10 +++---- .../uwauv/uwauvctrer-simple-module.h | 6 ++-- DESERT_Addons/uwauv/uwauverror-module.cc | 10 +++---- DESERT_Addons/uwauv/uwauverror-module.h | 28 +++++++++---------- .../uwauv/uwauverror-simple-module.cc | 4 +-- .../uwauv/uwauverror-simple-module.h | 28 +++++++++---------- 7 files changed, 46 insertions(+), 46 deletions(-) diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.h b/DESERT_Addons/uwauv/uwauvctrer-module.h index 6998c72e..2f59e67a 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-module.h +++ b/DESERT_Addons/uwauv/uwauvctrer-module.h @@ -56,9 +56,9 @@ class UwAUVErrorSendTimer : public UwSendTimer { public: /** - * Conscructor of UwSendTimer class - * @param UwAUVCtrModule *m pointer to an object of type UwAUVCtrModule - */ + * Conscructor of UwSendTimer class + * @param UwAUVCtrModule *m pointer to an object of type UwAUVCtrModule + */ UwAUVErrorSendTimer(UwAUVCtrErModule *m) : UwSendTimer((UwCbrModule*)(m)){ }; }; diff --git a/DESERT_Addons/uwauv/uwauvctrer-simple-module.cc b/DESERT_Addons/uwauv/uwauvctrer-simple-module.cc index 221c296b..e9f9a312 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-simple-module.cc +++ b/DESERT_Addons/uwauv/uwauvctrer-simple-module.cc @@ -51,15 +51,15 @@ static class UwAUVCtrErSimpleModuleClass : public TclClass { public: /** - * Constructor of the class - */ + * 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 - */ + * Creates the TCL object needed for the tcl language interpretation + * @return Pointer to an TclObject + */ TclObject* create(int, const char*const*) { return (new UwAUVCtrErSimpleModule()); } diff --git a/DESERT_Addons/uwauv/uwauvctrer-simple-module.h b/DESERT_Addons/uwauv/uwauvctrer-simple-module.h index 7a0903e4..6b48ba58 100644 --- a/DESERT_Addons/uwauv/uwauvctrer-simple-module.h +++ b/DESERT_Addons/uwauv/uwauvctrer-simple-module.h @@ -56,9 +56,9 @@ class UwAUVErrorSendTimer : public UwSendTimer { public: /** - * Conscructor of UwSendTimer class - * @param UwAUVCtrModule *m pointer to an object of type UwAUVCtrModule - */ + * Conscructor of UwSendTimer class + * @param UwAUVCtrModule *m pointer to an object of type UwAUVCtrModule + */ UwAUVErrorSendTimer(UwAUVCtrErSimpleModule *m) : UwSendTimer((UwCbrModule*)(m)){ }; }; diff --git a/DESERT_Addons/uwauv/uwauverror-module.cc b/DESERT_Addons/uwauv/uwauverror-module.cc index e7d3cde0..64d9af37 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.cc +++ b/DESERT_Addons/uwauv/uwauverror-module.cc @@ -57,15 +57,15 @@ static class UwAUVErrorModuleClass : public TclClass { public: /** - * Constructor of the class - */ + * 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 - */ + * Creates the TCL object needed for the tcl language interpretation + * @return Pointer to an TclObject + */ TclObject* create(int, const char*const*) { return (new UwAUVErrorModule()); } diff --git a/DESERT_Addons/uwauv/uwauverror-module.h b/DESERT_Addons/uwauv/uwauverror-module.h index 598f0bb2..fc47a6b8 100644 --- a/DESERT_Addons/uwauv/uwauverror-module.h +++ b/DESERT_Addons/uwauv/uwauverror-module.h @@ -54,9 +54,9 @@ class UwAUVErrorSendTimer : public UwSendTimer { public: /** - * Conscructor of UwAUVErrorSendTimer class - * @param UwAUVCtrModule *m pointer to an object of type UwAUVCtrModule - */ + * Conscructor of UwAUVErrorSendTimer class + * @param UwAUVCtrModule *m pointer to an object of type UwAUVCtrModule + */ UwAUVErrorSendTimer(UwAUVErrorModule *m) : UwSendTimer((UwCbrModule*)(m)){ }; }; @@ -85,20 +85,20 @@ class UwAUVErrorModule : public UwCbrModule { 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. - * - **/ + * 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. - */ + * 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) ; /** diff --git a/DESERT_Addons/uwauv/uwauverror-simple-module.cc b/DESERT_Addons/uwauv/uwauverror-simple-module.cc index ca6c9ea9..b0985056 100644 --- a/DESERT_Addons/uwauv/uwauverror-simple-module.cc +++ b/DESERT_Addons/uwauv/uwauverror-simple-module.cc @@ -53,8 +53,8 @@ static class UwAUVErrorSimpleModuleClass : public TclClass { public: /** - * Constructor of the class - */ + * Constructor of the class + */ UwAUVErrorSimpleModuleClass() : TclClass("Module/UW/AUV/ERS") { } diff --git a/DESERT_Addons/uwauv/uwauverror-simple-module.h b/DESERT_Addons/uwauv/uwauverror-simple-module.h index e893b70b..a7af5a35 100644 --- a/DESERT_Addons/uwauv/uwauverror-simple-module.h +++ b/DESERT_Addons/uwauv/uwauverror-simple-module.h @@ -54,9 +54,9 @@ class UwAUVErrorSendTimer : public UwSendTimer { public: /** - * Conscructor of UwSendTimer class - * @param UwAUVCtrModule *m pointer to an object of type UwAUVCtrModule - */ + * Conscructor of UwSendTimer class + * @param UwAUVCtrModule *m pointer to an object of type UwAUVCtrModule + */ UwAUVErrorSendTimer(UwAUVErrorSimpleModule *m) : UwSendTimer((UwCbrModule*)(m)){ }; }; @@ -85,20 +85,20 @@ class UwAUVErrorSimpleModule : public UwCbrModule { 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. - * - **/ + * 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. - */ + * 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) ; /**