50 : TclClass(
"Module/UW/PosBasedRt")
73 bind(
"ROV_speed_", (
double *) &
ROV_speed);
75 std::cout <<
" UwPosBasedRt::maxTxRange value not valid, value set by "
76 <<
"default to 3000 m" << std::endl;
80 std::cout <<
" UwPosBasedRt::ROV_speed value not valid, value set by "
81 <<
"defaul to 1 m/s" << std::endl;
94 Tcl &tcl = Tcl::instance();
97 if (strcasecmp(argv[1],
"setMaxTxRange") == 0) {
98 if (atof(argv[2]) <= 0) {
99 std::cerr <<
" UwPosBasedRt(IP=" <<(int)
ipAddr <<
")::invalid "
100 <<
"value for max transmission range, use a value >= 0";
106 if (strcasecmp(argv[1],
"addr") == 0) {
107 ipAddr =
static_cast<uint8_t
>(atoi(argv[2]));
109 std::cerr <<
"UwPosBasedRt::0 is not a valid IP address"
115 if (strcasecmp(argv[1],
"setNodePosition") == 0) {
116 Position *p =
dynamic_cast<Position*
> (tcl.lookup(argv[2]));
118 std::cout << NOW <<
" UwPosBasedRt(IP=" <<(int)
ipAddr
119 <<
")::node position, x: " <<
node_pos.getX() <<
", y: "
123 }
else if (argc == 5) {
124 if (strcasecmp(argv[1],
"addRoute") == 0) {
125 if (strcasecmp(argv[4],
"toMovingNode") == 0) {
126 addRoute(
static_cast<uint8_t
>(atoi(argv[2])),
127 static_cast<uint8_t
>(atoi(argv[3])),0);
129 }
else if (strcasecmp(argv[4],
"toFixedNode") == 0) {
130 addRoute(
static_cast<uint8_t
>(atoi(argv[2])),
131 static_cast<uint8_t
>(atoi(argv[3])),1);
134 std::cerr <<
"UwPosBasedRt::invalid command, set "
135 <<
"\"toFixedNode\" or \"toMovingNode\" "<< std::endl;
140 return Module::command(argc, argv);
148 std::cout << NOW <<
" UwPosBasedRt(IP=" <<(int)
ipAddr
149 <<
")::node IP addres not set, drop packet" << std::endl;
153 hdr_cmn *ch = HDR_CMN(p);
156 if (ch->direction() == hdr_cmn::UP) {
163 std::cout << NOW <<
" UwPosBasedRt(IP="
164 <<(int)
ipAddr <<
")::packet for me, send up" << std::endl;
170 if (ch->next_hop() == 0) {
171 std::cout << NOW <<
" UwPosBasedRt(IP=" <<(int)
ipAddr
172 <<
")::next hop not found, drop packet" << std::endl;
176 std::cout << NOW <<
" UwPosBasedRt(IP=" <<(int)
ipAddr
177 <<
")::next hop: " << (
int)ch->next_hop() << std::endl;
187 if (ch->next_hop() == 0) {
189 std::cout << NOW <<
" UwPosBasedRt(IP=" <<(int)
ipAddr
190 <<
")::next hop not found, drop packet" << std::endl;
195 std::cout << NOW <<
" UwPosBasedRt(IP=" <<(int)
ipAddr
196 <<
")::next hop: " << (
int)ch->next_hop() << std::endl;
212 std::map<uint8_t, UwPosEstimation>::iterator itROV =
216 Position tempLastROVpos = (itROV->second).getInitPos();
217 Position tempLastWp = (itROV->second).getDest();
220 pbrh->
x_ROV() = tempLastROVpos.getX();
221 pbrh->
y_ROV() = tempLastROVpos.getY();
222 pbrh->
z_ROV() = tempLastROVpos.getZ();
226 pbrh->
timestamp() = (itROV->second).getTimestamp();
227 pbrh->
ROV_speed() = (itROV->second).getSpeed();
231 std::cout << NOW <<
" UwPosBasedRt(IP=" <<(int)
ipAddr
232 <<
")::information inserted"
236 <<
" ,x ROV: " << pbrh->
x_ROV()
237 <<
" ,y ROV: " << pbrh->
y_ROV()
238 <<
" ,z ROV: " << pbrh->
z_ROV()
241 <<
" ,ROV IP: " << (int)pbrh->
IP_ROV() << std::endl;
244 std::cout << NOW <<
" UwPosBasedRt(IP=" <<(int)
ipAddr
245 <<
")::initPacket, dest addr not found "
246 <<
" in ROV routing table" << std::endl;
258 std::map<uint8_t, UwPosEstimation>::iterator itROV =
262 if ((itROV->second).getTimestamp() < pbrh->
timestamp()) {
264 Position tempLastROVpos;
265 tempLastROVpos.setX(pbrh->
x_ROV());
266 tempLastROVpos.setY(pbrh->
y_ROV());
267 tempLastROVpos.setZ(pbrh->
z_ROV());
272 (itROV->second).update(tempLastROVpos,tempLastWp,
275 Position provvInitPos = (itROV->second).getInitPos();
276 Position provvDest = (itROV->second).getDest();
278 std::cout << NOW <<
" UwPosBasedRt(IP=" <<(int)
ipAddr
279 <<
")::update node info" << std::endl;
280 std::cout << NOW <<
" UwPosBasedRt(IP=" <<(int)
ipAddr
281 <<
")::information setted in the node"
282 <<
", x ROV: " << provvInitPos.getX()
283 <<
" ,y ROV: " << provvInitPos.getY()
284 <<
" ,z ROV: " << provvInitPos.getZ()
285 <<
" ,x wp: " << provvDest.getX()
286 <<
" ,y wp: " << provvDest.getY()
287 <<
" ,z wp: " << provvDest.getZ()
288 <<
" ,timestamp: " << (itROV->second).getTimestamp()
289 <<
" ,ROV speed: " << (itROV->second).getSpeed()
294 Position tempLastROVpos = (itROV->second).getInitPos();
295 Position tempLastWp = (itROV->second).getDest();
296 pbrh->
x_ROV() = tempLastROVpos.getX();
297 pbrh->
y_ROV() = tempLastROVpos.getY();
298 pbrh->
z_ROV() = tempLastROVpos.getZ();
302 pbrh->
timestamp() = (itROV->second).getTimestamp();
303 pbrh->
ROV_speed() = (itROV->second).getSpeed();
306 std::cout << NOW <<
" UwPosBasedRt(IP=" <<(int)
ipAddr
307 <<
")::update packet info" << std::endl;
308 std::cout << NOW <<
" UwPosBasedRt(IP=" <<(int)
ipAddr
309 <<
")::information setted in the packet"
313 <<
" ,x ROV: " << pbrh->
x_ROV()
314 <<
" ,y ROV: " << pbrh->
y_ROV()
315 <<
" ,z ROV: " << pbrh->
z_ROV()
317 <<
" ,ROV speed: " << pbrh->
ROV_speed() << std::endl;
329 std::map<uint8_t, UwPosEstimation>::iterator itROV =
332 Position tempEstim = (itROV->second).getEstimatePos(NOW);
335 std::cout << NOW <<
" UwPosBasedRt(IP=" <<(int)
ipAddr
336 <<
")::estimated ROV position, x ROV: " << tempEstim.getX()
337 <<
" ,y ROV: " << tempEstim.getY()
338 <<
" ,z ROV: " << tempEstim.getZ() << std::endl;
342 std::cout << NOW <<
" UwPosBasedRt(IP=" <<(int)
ipAddr <<
")::" <<
343 "estimated distance between node and ROV " << dist << std::endl;
347 std::cout << NOW <<
" UwPosBasedRt(IP=" <<(int)
ipAddr
348 <<
")::forward directly to ROV" <<std::endl;
352 std::cout << NOW <<
" UwPosBasedRt(IP=" <<(int)
ipAddr
353 <<
")::ROV is not in the tx range" <<std::endl;
358 std::map<uint8_t, uint8_t>::const_iterator it =
362 std::cout << NOW <<
" UwPosBasedRt(IP=" <<(int)
ipAddr
363 <<
")::routing table, entry found (dest,next hop)=("
364 << (
int)it->first<<
"," << (int)it->second<<
")" << std::endl;
376 double x1 = p1.getX();
377 double y1 = p1.getY();
378 double z1 = p1.getZ();
379 double x2 = p2.getX();
380 double y2 = p2.getY();
381 double z2 = p2.getZ();
383 return sqrt(pow(x2-x1,2) + pow(y2-y1,2) + pow(z2-z1,2));
387 const uint8_t &dst,
const uint8_t &next,
const int toFixedNode)
390 std::cout << NOW <<
" UwPosBasedRt(IP=" <<(int)
ipAddr
391 <<
")::invalid IP address equal to 0" << std::endl;
394 if (toFixedNode == 0) {
396 std::map<uint8_t, UwPosEstimation>::iterator itROV =
400 std::cout << NOW <<
" UwPosBasedRt(IP=" <<(int)
ipAddr
401 <<
")::entry for ROV routing yet present" << std::endl;
405 std::cout << NOW <<
" UwPosBasedRt(IP=" <<(int)
ipAddr
406 <<
")::inserted entry for ROV routing" << std::endl;
413 std::map<uint8_t, uint8_t>::iterator it =
static_routing.find(dst);
420 std::cout << NOW <<
" UwPosBasedRt(IP=" <<(int)
ipAddr
421 <<
")::addRoute, inserted entry (dest=" << (
int)dst
422 <<
",next="<< (int)next <<
")" <<std::endl;
431 std::cout << NOW <<
" UwPosBasedRt(IP=" <<(int)
ipAddr
432 <<
")::value for max transmission range not valid" << std::endl;
437 std::cout << NOW <<
" UwPosBasedRt(IP=" <<(int)
ipAddr
438 <<
")::max transmission range set to " <<
maxTxRange << std::endl;
UwPosBasedRtModuleClass()
TclObject * create(int, const char *const *)
virtual int command(int, const char *const *)
TCL command interpreter.
double ROV_speed
Last known ROV speed.
virtual ~UwPosBasedRt()
Destructor of UwPosBasedRt class.
virtual void recv(Packet *p)
Performs the reception of packets from upper and lower layers.
virtual void setMaxTxRange(double newRange)
Set maximum transmission range.
virtual void addRoute(const uint8_t &dst, const uint8_t &next, const int toFixedNode)
Add new entry to the routing table.
double maxTxRange
Maximum transmission range, in meters, for this node.
std::map< uint8_t, uint8_t > static_routing
Routing table: destination - next hop.
virtual uint8_t findNextHop(const Packet *p)
Find next hop of a packet passed as input.
virtual void updatePosInfo(Packet *p)
update informations regardin position, if needed
Position node_pos
Position of this node.
UwPosBasedRt()
Constructor of UwPosBasedRt class.
int debug_
Flag to enable or disable dirrefent levels of debug.
std::map< uint8_t, UwPosEstimation > ROV_routing
Rouitng table for ROV.
virtual void initPkt(Packet *p)
Initialize field of hdr_uwpos_based_rt
virtual double nodesDistance(Position &p1, Position &p2)
Compute absoulute distance between 2 nodes.
hdr_uwip describes UWIP packets.
uint8_t & daddr()
Reference to the daddr_ variable.
hdr_uwpos_based_rt describes packets used by UWPOSBASEDRT.
#define HDR_UWPOS_BASED_RT(p)
UwPosBasedRtModuleClass class_module_uwposbasedrt
packet_t PT_UWPOSITIONBASEDROUTING
Routing protocol for static node based on ROV position.
#define DROP_NEXT_HOP_NOT_FOUND