DESERT 3.5.1
Loading...
Searching...
No Matches
uwrovctr-module.cc
Go to the documentation of this file.
1//
2// Copyright (c) 2017 Regents of the SIGNET lab, University of Padova.
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions
7// are met:
8// 1. Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// 2. Redistributions in binary form must reproduce the above copyright
11// notice, this list of conditions and the following disclaimer in the
12// documentation and/or other materials provided with the distribution.
13// 3. Neither the name of the University of Padova (SIGNET lab) nor the
14// names of its contributors may be used to endorse or promote products
15// derived from this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
39#include "uwrovctr-module.h"
40#include <iostream>
41#include <rng.h>
42#include <stdint.h>
43extern packet_t PT_UWCBR;
44extern packet_t PT_UWROV;
45extern packet_t PT_UWROV_CTR;
46
54static class UwROVCtrModuleClass : public TclClass {
55public:
56
60 UwROVCtrModuleClass() : TclClass("Module/UW/ROV/CTR") {
61 }
62
67 TclObject* create(int, const char*const*) {
68 return (new UwROVCtrModule());
69 }
71
73 : UwCbrModule()
74 , sn(0)
75 , adaptiveRTO(0)
76 , adaptiveRTO_parameter(0.5)
77 //, sumrttAck(0)
78 //, rttAcksamples(0)
79{
80 posit=p;
81 speed=1;
82 bind("adaptiveRTO_", (int *) &adaptiveRTO);
83 if (adaptiveRTO == 1) {
84 bind("adaptiveRTO_parameter_", (double *) &adaptiveRTO_parameter);
85 }
86 if (adaptiveRTO_parameter < 0) {
87 cerr << NOW << "Invalid adaptive RTO parameter < 0, set to 0.5 "
88 << "by default " << std::endl;
90 }
91}
92
94 : UwCbrModule()
95 , sn(0)
96 , adaptiveRTO(0)
97 , adaptiveRTO_parameter(0.5)
98 //, sumrttAck(0)
99 //, rttAcksamples(0)
100{
101 p = NULL;
102 posit = Position();
103 speed = 1;
104 bind("adaptiveRTO_", (int *) &adaptiveRTO);
105 if (adaptiveRTO == 1) {
106 bind("adaptiveRTO_parameter_", (double *) &adaptiveRTO_parameter);
107 }
108 if (adaptiveRTO_parameter < 0) {
109 cerr << NOW << "Invalide adaptive RTO parameter < 0, set to 0.5 "
110 << "by default " << std::endl;
112
113 }
114
115}
116
118
119int UwROVCtrModule::command(int argc, const char*const* argv) {
120 Tcl& tcl = Tcl::instance();
121 if(argc == 2){
122 if (strcasecmp(argv[1], "getROVMonheadersize") == 0) {
123 tcl.resultf("%d", this->getROVMonHeaderSize());
124 return TCL_OK;
125 }
126 else if(strcasecmp(argv[1], "getROVctrheadersize") == 0) {
127 tcl.resultf("%d", this->getROVCTRHeaderSize());
128 return TCL_OK;
129 }
130 else if(strcasecmp(argv[1], "getX") == 0) {
131 tcl.resultf("%f", posit.getX());
132 return TCL_OK;
133 }
134 else if(strcasecmp(argv[1], "getY") == 0) {
135 tcl.resultf("%f", posit.getY());
136 return TCL_OK;
137 }
138 else if(strcasecmp(argv[1], "getZ") == 0) {
139 tcl.resultf("%f", posit.getZ());
140 return TCL_OK;
141 }
142 }
143 else if(argc == 3){
144 if (strcasecmp(argv[1], "setPosition") == 0) {
145 Position* p = dynamic_cast<Position*> (tcl.lookup(argv[2]));
146 posit = *p;
147 return TCL_OK;
148 } else if (strcasecmp(argv[1], "setSpeed") == 0) {
149 speed = atof(argv[2]);
150 return TCL_OK;
151 } else if (strcasecmp(argv[1], "setAdaptiveRTOparameter") == 0) {
152 adaptiveRTO_parameter = atof(argv[2]);
153 return TCL_OK;
154 }
155 }
156 else if(argc == 5){
157 if (strcasecmp(argv[1], "sendPosition") == 0) {
158 newX = atof(argv[2]);
159 newY = atof(argv[3]);
160 newZ = atof(argv[4]);
161 this->reset_retx();
162 this->transmit();
163 tcl.resultf("%s", "position Setted");
164 return TCL_OK;
165 }
166 }else if(argc == 6){
167 if (strcasecmp(argv[1], "sendPosition") == 0) {
168 newX = atof(argv[2]);
169 newY = atof(argv[3]);
170 newZ = atof(argv[4]);
171 speed = atof(argv[5]);
172 this->reset_retx();
173 this->transmit();
174 tcl.resultf("%s", "position Setted");
175 return TCL_OK;
176 }
177 }
178 return UwCbrModule::command(argc,argv);
179}
180
182 sendPkt();
183
184 if (adaptiveRTO == 1 && rttsamples > 0) {
186 if (debug_) {
187 std::cout << NOW << " UwROVCtrModule::RTO set to " << period_
188 << std::endl;
189 }
190 }
191
192 sendTmr_.resched(period_);
193}
194
196
198 posit = p;
199}
200
201void UwROVCtrModule::initPkt(Packet* p) {
202 if(this->p == NULL){
203 hdr_uwROV_ctr* uwROVh = HDR_UWROV_CTR(p);
204 uwROVh -> x() = newX;
205 uwROVh->y() = newY;
206 uwROVh->z() = newZ;
207 uwROVh->speed() = speed;
208 uwROVh->sn() = ++sn;
209 this->p = p;
210 }
211 else{
212 hdr_uwROV_ctr* uwROVh = HDR_UWROV_CTR(p);
213 uwROVh->x() = newX;
214 uwROVh->y() = newY;
215 uwROVh->z() = newZ;
216 uwROVh->speed() = speed;
217 uwROVh->sn() = sn;
218 if (debug_) {
219 std::cout << NOW << " UwROVCtrModule::initPkt(Packet *p) "
220 << "Retransmitting"<< std::endl;
221 }
222 }
223
224 if (debug_) {
225 if (rttsamples > 0) {
226 std::cout << NOW << " RTT UwROVCtr: " << sumrtt/rttsamples
227 << " s" << std::endl;
228 }
229 }
230
232 if (debug_) {
233 hdr_uwROV_ctr* uwROVh = HDR_UWROV_CTR(p);
234 std::cout << NOW << " UwROVCtrModule::initPkt(Packet *p) setting new"
235 << " ROV way-point: X = "<< uwROVh->x() <<", Y = "
236 << uwROVh->y() << ", Z = " << uwROVh->z()<< std::endl;
237 }
238}
239
240void UwROVCtrModule::recv(Packet* p, Handler* h) {
241 recv(p);
242}
243
244void UwROVCtrModule::recv(Packet* p) {
246 x_rov = monitoring->x();
247 y_rov = monitoring->y();
248 z_rov = monitoring->z();
249
250
251 hdr_uwcbr *uwcbrh = HDR_UWCBR(p);
252 hdr_cmn *ch = hdr_cmn::access(p);
253 if(monitoring->ack() == sn + 1) {
254 sendTmr_.force_cancel();
255 this->p = NULL;
256 }
257
258 if(monitoring->ack() > 0 && debug_)
259 std::cout << NOW << " UwROVCtrModule::recv(Packet *p) control ACK "
260 << "received " << monitoring->ack()<< std::endl;
261 else if((monitoring->ack())<0 && debug_)
262 std::cout << NOW << " UwROVCtrModule::recv(Packet *p) control error "
263 <<"received"<< std::endl;
264 if (debug_ > 10)
265 std::cout << NOW << " UwROVCtrModule::recv(Packet *p) ROV monitoring "
266 << "position: X = " << x_rov << ", Y = " << y_rov
267 << ", Z = " << z_rov << std::endl;
268
270
271}
UwCbrModule class is used to manage UWCBR packets and to collect statistics about them.
virtual void initPkt(Packet *p)
Initializes a data packet passed as argument with the default values.
int debug_
Flag to enable several levels of debug.
UwSendTimer sendTmr_
Timer which schedules packet transmissions.
double sumrtt
Sum of RTT samples.
virtual void recv(Packet *)
Performs the reception of packets from upper and lower layers.
virtual int command(int argc, const char *const *argv)
TCL command interpreter.
double period_
Period between two consecutive packet transmissions.
virtual void sendPkt()
Allocates, initialize and sends a packet with the default priority flag set from tcl.
int rttsamples
Number of RTT samples.
Adds the module for UwROVModuleClass in ns2.
UwROVCtrModuleClass()
Constructor of the class.
TclObject * create(int, const char *const *)
Creates the TCL object needed for the tcl language interpretation.
UwROVCtrModule class is used to manage UWROVCtr packets and to collect statistics about them.
float y_rov
Y of the last ROV position monitored.
Packet * p
Sequence number of the last control packet sent.
int adaptiveRTO
1 if an adaptive RTO is used, 0 if a constant RTO is used.
virtual int command(int argc, const char *const *argv)
TCL command interpreter.
virtual ~UwROVCtrModule()
Destructor of UwROVCtrModule class.
float x_rov
X of the last ROV position monitored.
float newY
Y of the new position sent to the ROV.
virtual void start()
Start the controller.
double adaptiveRTO_parameter
Parameter for the adaptive RTO.
float newZ
Z of the new position sent to the ROV.
static int getROVCTRHeaderSize()
Returns the size in byte of a hdr_uwROV_ctr packet header.
float z_rov
Z of the last ROV position monitored.
float newX
X of the new position sent to the ROV.
void reset_retx()
Reset retransmissions.
virtual void initPkt(Packet *p)
Initializes a control data packet passed as argument with the default values.
virtual void recv(Packet *)
Performs the reception of packets from upper and lower layers.
Position posit
Controller position.
static int getROVMonHeaderSize()
Returns the size in byte of a hdr_uwROV_monitoring packet header.
virtual void setPosition(Position p)
Set the position of the ROVCtr.
virtual void transmit()
Creates and transmits a packet.
UwROVCtrModule()
Constructor of UwROVCtrModule class.
float speed
Moving speed sent to the ROV.
hdr_uwROV_ctr describes UWROV_ctr packets for controlling the ROV.
float & z()
double & sn()
float & speed()
float & x()
float & y()
hdr_uwROV_monitoring describes UWROV_monitoring packets sent by the ROV to the base station for monit...
hdr_uwcbr describes UWCBR packets.
#define HDR_UWCBR(p)
packet_t PT_UWROV
UwROVCtrModuleClass class_module_uwROV_ctr
packet_t PT_UWROV_CTR
Provides the definition of the class UWROV.
#define HDR_UWROV_MONITORING(p)
#define HDR_UWROV_CTR(p)