DESERT 3.5.1
Loading...
Searching...
No Matches
sun-ipr-node-data.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"
41
42extern packet_t PT_SUN_DATA;
43extern packet_t PT_SUN_PATH_EST;
44
45/* This function initialize a Data Packet passed as argument with the values
46 * contained in the routing table.
47 */
48void
50{
51 if (STACK_TRACE)
52 std::cout << "> initPktDataPacket()" << std::endl;
53
54 // Common header.
55 hdr_cmn *ch = HDR_CMN(p);
56 // ch->uid() = 0; // Set by the Application above.
57 // ch->ptype() = 0; // Set by the Application above.
58 // ch->size() = 0; // Look Down;
59 ch->direction() = hdr_cmn::DOWN;
60 // ch->next_hop() = 0; // This value must be set by the invoker.
61 // ch->prev_hop_ = ipAddr_;
62
63 // IP Header.
64 hdr_uwip *iph = HDR_UWIP(p);
65 iph->daddr() = sink_associated; // The destination is always the Sink associated.
66 // iph->dport() = 0; // Set by the Application above.
67 iph->saddr() = ipAddr_;
68 // iph->sport() = 0; // Set by the Application above.
69
70 // Path establishment header.
72 hdata->list_of_hops_length() = this->getNumberOfHopToSink() - 1;
73 for (int i = 0; i < hop_table_length; i++) {
74 hdata->list_of_hops()[i] = hop_table[i];
75 }
76 hdata->pointer() = 0;
77
78 ch->size() += sizeof(hdr_sun_data);
79 ch->timestamp() = Scheduler::instance().clock();
80} /* SunIPRoutingNode::initPktDataPacket */
81
82/* Use this function only if the invoker is a node with hop_to_sink > 1,
83 * otherwise: drop.
84 * This function is used by a node to forward a data packet to the next hop.
85 * All the information to route the packet are contained in the packet.
86 */
87void
89{
90 if (STACK_TRACE)
91 std::cout << "> forwardDataPacket()" << std::endl;
92 hdr_cmn *ch = HDR_CMN(p);
93 hdr_uwip *iph = HDR_UWIP(p);
95
96 if (hdata->list_of_hops_length() <= 0) { // Garbage Packet.
98 } else if (hdata->list_of_hops_length() > 0) { // The current node acts as relay.
99 int i_ = hdata->pointer();
100 if (hdata->list_of_hops()[i_] == ipAddr_) { // If I'm the right next hop.
101 if (this->getNumberOfHopToSink() == 1) { // Send to the sink.
102 ch->next_hop() = sink_associated;
103 ch->prev_hop_ = ipAddr_;
104 } else { // Forward to the next node.
105 ch->next_hop() = hdata->list_of_hops()[i_ + 1];
106 ch->prev_hop_ = ipAddr_;
107 hdata->pointer()++;
108 }
109
110 if (printDebug_ > 5) {
111 std::cout << "[" << NOW
112 << "]::Node[IP:" << this->printIP(ipAddr_)
113 << "||hops:" << this->getNumberOfHopToSink()
114 << "]::PACKET::UID:" << ch->uid()
115 << "::SRC:" << printIP(iph->saddr())
116 << "::DST:" << printIP(iph->daddr())
117 << "::FORWARDED_TO:" << printIP(ch->next_hop())
118 << std::endl;
119 }
120
123 double delay_tx_ = this->getDelay(period_data_);
124 pkt_tx_++;
125 if (trace_)
126 this->tracePacket(p, "FRWD_DTA");
127 sendDown(p, delay_tx_);
128 } else {
129 Packet::free(p);
130 }
131 }
132} /* SunIPRoutingNode::forwardDataPacket */
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.
static long number_of_datapkt_
Comulative number of Data packets processed by SunIPRoutingNode objects.
virtual void initPktDataPacket(Packet *)
Initializes a data packet passed as argument with the default values.
nsaddr_t * hop_table
List of IPs to reach the sink.
virtual void forwardDataPacket(Packet *)
Forwards a data packet to the next hop.
bool trace_
Flag used to enable or disable the trace file for nodes,.
virtual const int & getNumberOfHopToSink() const
Returns the number of hops that separate the node to the sink.
int hop_table_length
Current length of the hop_table.
static long number_of_pkt_forwarded_
Comulative number of Data packets forwarded by the network.
nsaddr_t sink_associated
IP of the sink associated to the node.
double period_data_
Period of the Poisson traffic for data packets in the buffer.
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 tracePacket(const Packet *const, const string &position="UNDEF___")
Traces a packet.
nsaddr_t ipAddr_
IP of the current node.
long pkt_tx_
Keep track of the total number of packet retransmitted.
hdr_sun_data describes data packets used by UWSUN
uint8_t * list_of_hops()
Pointer to the list_of_hops_ variable.
hdr_uwip describes UWIP packets.
Definition uwip-module.h:70
#define HDR_SUN_DATA(p)
#define DROP_DATA_HOPS_LENGTH_EQUALS_ZERO
Reason for a drop in a UWSUN module.
#define STACK_TRACE
Used to keep track of methods call.
Dinamic source routing protocol, this file contains Nodes specifications.
#define HDR_UWIP(P)
Definition uwip-module.h:58