DESERT 3.5.1
Loading...
Searching...
No Matches
sun-ipr-node-ack.cpp
Go to the documentation of this file.
1//
2// Copyright (c) 2021 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//
29
40#include "sun-ipr-node.h"
42
43/* This function uses the value contained in the header of a uwcbr packet.
44 * TODO: try to modifies this in order to use the ch->uid() field instead.
45 */
46void
48{
49 if (STACK_TRACE)
50 std::cout << "> sendBackAck()" << std::endl;
51 hdr_cmn *ch = HDR_CMN(p);
53
54 Packet *p_ack = Packet::alloc();
55 this->initPktAck(p_ack);
56
60
61 ch_ack->next_hop() = ch->prev_hop_;
62 iph_ack->daddr() = ch->prev_hop_;
63 hack->uid() = uwcbrh->sn();
64
65 if (printDebug_ > 5) {
66 std::cout << "[" << NOW
67 << "]::Node[IP:" << this->printIP(ipAddr_)
68 << "||hops:" << this->getNumberOfHopToSink()
69 << "]::ACK_SENT_TO:" << printIP(ch_ack->next_hop())
70 << "::SN:" << uwcbrh->sn()
71 << std::endl;
72 }
74 if (trace_)
75 this->tracePacket(p_ack, "SEND_ACK");
76 sendDown(p_ack, this->getDelay(period_status_));
77} /* SunIPRoutingNode::sendBackAck */
78
79void
81{
82 if (STACK_TRACE)
83 std::cout << "> initPktPathEstSearch()" << std::endl;
84
85 // Common header.
86 hdr_cmn *ch = HDR_CMN(p);
87 ch->uid() = sunuid_++;
88 ch->ptype() = PT_SUN_ACK;
89 // ch->size() = 0; // Look down.
90 ch->direction() = hdr_cmn::DOWN;
91 // ch->next_hop() = 0;
92 ch->prev_hop_ = ipAddr_;
93
94 // IP header.
95 // hdr_uwip* iph = HDR_UWIP(p);
96 // iph->daddr() = 0;
97 // iph->dport() = 0;
98 // iph->saddr() = 0;
99 // iph->sport() = 0;
100
101 ch->size() += sizeof(hdr_sun_ack);
102 ch->timestamp() = Scheduler::instance().clock();
103} /* SunIPRoutingNode::initPktAck */
104
105/* This function is used to create a route error packet. This packet will be
106 * sent by the current node to the source of the data packet that generated the
107 * error. The packet created by this function is a path establishment packet
108 * with the type field set to PATH_ERROR.
109 */
110void
111SunIPRoutingNode::createRouteError(const Packet *p_data, Packet *p)
112{ // p is a path establishment packet beacause it contains a list of hops.
113 if (printDebug_ > 5) {
114 std::cout << "[" << NOW
115 << "]::Node[IP:" << this->printIP(ipAddr_)
116 << "||hops:" << this->getNumberOfHopToSink()
117 << "]::GENERATING_ROUTE_ERROR"
118 << std::endl;
119 }
120 if (STACK_TRACE)
121 std::cout << "> createRouteError()" << std::endl;
122 this->initPktPathEstSearch(p);
126 hdr_cmn *ch = HDR_CMN(p);
127 hdr_uwip *iph = HDR_UWIP(p);
129
130 ch->prev_hop_ = ipAddr_;
131 if (ch_data->prev_hop_ ==
132 iph_data->saddr()) { // Trick to fix the case in which the node that
133 // generates the error is one hop distant from
134 // the source.
135 ch->next_hop() = ch_data->prev_hop_;
136 } else {
137 ch->next_hop() = hdata->list_of_hops()[hdata->pointer() - 1];
138 }
139
140 iph->saddr() = ipAddr_;
141 iph->daddr() = iph_data->saddr();
142
143 hpest->ptype() = PATH_ERROR;
144 hpest->list_of_hops_length() =
145 hdata->pointer(); // Not + 1 because the current node is excluded.
146 hpest->pointer() = 1;
147
148 // Hops from the current node to the source of the data packet.
149 int w_ = hdata->pointer() - 1;
150 // cout << "createRouteError(), node:" << printIP(ipAddr_) << ":" <<
151 // printIP(iph->daddr()) << endl;
152 for (int i = 0; i < hdata->pointer(); i++) {
153 hpest->list_of_hops()[i] = hdata->list_of_hops()[w_];
154 // cout << i << ":" << printIP(hpest->list_of_hops()[i]) << endl;
155 w_--;
156 }
157} /* SunIPRoutingNode::createRouteError */
158
159void
161{
162 if (STACK_TRACE)
163 std::cout << "> sendRouteErrorBack()" << std::endl;
164 hdr_cmn *ch = HDR_CMN(p);
165 hdr_uwip *iph = HDR_UWIP(p);
167
168 if (hpest->pointer() < hpest->list_of_hops_length()) {
169 ch->next_hop() = hpest->list_of_hops()[hpest->pointer()];
170 } else {
171 ch->next_hop() = iph->daddr();
172 }
173 // cout << "ch->next_hop():" << printIP(ch->next_hop()) << endl;
174 hpest->pointer()--;
176 if (trace_)
177 this->tracePacket(p, "FRWD_ERR");
178 sendDown(p, this->getDelay(period_status_));
179} /* SunIPRoutingNode::sendRouteErrorBack */
static string printIP(const nsaddr_t &)
Returns a string with an IP in the classic form "x.x.x.x" converting an ns2 nsaddr_t address.
ostringstream osstream_
Used to convert to string.
virtual void createRouteError(const Packet *, Packet *)
Used to create a route error packet.
bool trace_
Flag used to enable or disable the trace file for nodes,.
static long number_of_ackpkt_
Comulative number of Ack packets processed by SunIPRoutingNode objects.
virtual const int & getNumberOfHopToSink() const
Returns the number of hops that separate the node to the sink.
virtual void initPktPathEstSearch(Packet *) const
Initializes a Path Establishment Search packet (previously allocated).
static long number_of_pathestablishment_
Comulative number of Path Establishment packets processed by SunIPRoutingNode objects.
virtual void initPktAck(Packet *)
Initializes an ack packet passed as argument with the default values.
double period_status_
Period of the Poisson traffic for status and ack packets.
virtual void sendBackAck(const Packet *)
Creates an ack packet and sends it to the previous hop using the information contained in the header ...
const double getDelay(const double &period_) const
Returns a delay value to use in transmission.
int printDebug_
Flag to enable or disable dirrefent levels of debug.
virtual void sendRouteErrorBack(Packet *)
Send back an error packet to the previous hop.
virtual void tracePacket(const Packet *const, const string &position="UNDEF___")
Traces a packet.
nsaddr_t ipAddr_
IP of the current node.
hdr_sun_ack describes acks packets used by UWSUN.
Definition sun-hdr-ack.h:52
hdr_sun_data describes data packets used by UWSUN
hdr_sun_path_est describes path establishment packets used by UWSUN
hdr_uwcbr describes UWCBR packets.
hdr_uwip describes UWIP packets.
Definition uwip-module.h:70
#define HDR_SUN_ACK(p)
Definition sun-hdr-ack.h:45
#define HDR_SUN_DATA(p)
#define PATH_ERROR
#define HDR_SUN_PATH_EST(p)
Common structures and definition used by SUN.
#define STACK_TRACE
Used to keep track of methods call.
static int sunuid_
Unique identifier for UWSUN packets.
Dinamic source routing protocol, this file contains Nodes specifications.
#define HDR_UWCBR(p)
#define HDR_UWIP(P)
Definition uwip-module.h:58