DESERT 3.5.1
Loading...
Searching...
No Matches
sun-ipr-node-loadmetric.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
41#include "sun-ipr-node.h"
42
43/* This function increases the counter of packets processed by the current node
44 */
45void
47{
48 if (STACK_TRACE)
49 std::cout << "> updatePacketsCount()" << std::endl;
50 double current_instant_ = Scheduler::instance().clock();
54 packets_array_full = true;
56} /* SunIPRoutingNode::updatePacketsCount */
57
58/* This function increases the counter of acks received by the current node */
59void
61{
62 if (STACK_TRACE)
63 std::cout << "> updateAcksCount()" << std::endl;
64 double current_instant_ = Scheduler::instance().clock();
67 if (pointer_acks_ + 1 >= LISTLENGTH)
68 acks_array_full = true;
70} /* SunIPRoutingNode::updateAcksCount */
71
72/* This function returns the number of packets processed by the current node
73 * in the last minute.
74 */
75const int
77{
78 if (STACK_TRACE)
79 std::cout << "> getPacketsLastMinute()" << std::endl;
80 long t_max_ = list_packets_max_time_;
81 long t_min_ = t_max_;
82 int position_min_ = 0;
83 // int position_max_ = pointer_packets_ - 1;
84 for (int i = 0; i < LISTLENGTH; i++) {
85 if ((list_packets[i] != 0) && (list_packets[i] < t_min_)) {
86 t_min_ = list_packets[i];
88 }
89 }
90 if (t_max_ == t_min_) {
91 return 0;
92 } else if ((t_max_ - t_min_) <=
93 MINUTE) { // More than LISTLENGTH per minute.
95 return int(MINUTE / (t_max_ - t_min_) * LISTLENGTH);
96 } else
97 return int(MINUTE / (t_max_ - t_min_));
98 } else {
99 for (int i = 0; i < LISTLENGTH; i++) {
101 t_min_ = list_packets[position_min_];
102 if ((t_max_ - t_min_) <= MINUTE) {
103 break;
104 }
105 }
106 if (t_max_ == t_min_) {
107 return 0;
108 } else {
109 return int(MINUTE / (t_max_ - t_min_) * LISTLENGTH);
110 }
111 }
112} /* SunIPRoutingNode::getPacketsLastMinute */
113
114/* This function returns the number of acks received by the current node
115 * in the last minute.
116 */
117const int
119{
120 if (STACK_TRACE)
121 std::cout << "> getAcksLastMinute()" << std::endl;
122 long t_max_ = list_acks_max_time_;
123 long t_min_ = t_max_;
124 int position_min_ = 0;
125 // int position_max_ = pointer_acks_ - 1;
126 for (int i = 0; i < LISTLENGTH; i++) {
127 if ((list_acks[i] != 0) && (list_acks[i] < t_min_)) {
128 t_min_ = list_acks[i];
130 }
131 }
132 if (t_max_ == t_min_) {
133 return 0;
134 } else if ((t_max_ - t_min_) <=
135 MINUTE) { // More than LISTLENGTH per minute.
136 if (acks_array_full)
137 return int(MINUTE / (t_max_ - t_min_) * LISTLENGTH);
138 else
139 return int(MINUTE / (t_max_ - t_min_));
140 } else {
141 for (int i = 0; i < LISTLENGTH; i++) {
143 t_min_ = list_acks[position_min_];
144 if ((t_max_ - t_min_) <= MINUTE)
145 break;
146 }
147 if (t_max_ == t_min_) {
148 return 0;
149 } else {
150 return int(MINUTE / (t_max_ - t_min_) * LISTLENGTH);
151 }
152 }
153} /* SunIPRoutingNode::getAcksLastMinute */
154
155const double
157{
158 if (STACK_TRACE)
159 std::cout << "> getLoad()" << std::endl;
161 int acks_ = getAcksLastMinute();
162 return packets_ * alpha_ + (packets_ - acks_) * (1 - alpha_);
163} /* SunIPRoutingNode::getLoad */
long list_acks_max_time_
Clock of the last ack received by the node.
int pointer_packets_
Pointer of the first avaiable space in list_packets list.
ostringstream osstream_
Used to convert to string.
static const int LISTLENGTH
Used by the load metric to set the number of the acks tracked.
virtual const int getPacketsLastMinute() const
Returns the number of packets processed by the current node in the last interval of time (MINUTE).
long list_packets_max_time_
Clock of the last packet received by the node.
virtual void updatePacketsCount()
Updates the number of packets processed by the current node.
virtual const int getAcksLastMinute() const
Returns the number of acks received by the current node in the last interval of time (MINUTE).
static const int MINUTE
Used by the load metric to set the period to consider for the evaluation of the metric.
virtual void updateAcksCount()
Updates the number of acks received by the current node.
double list_acks[LISTLENGTH]
List of the last LISTLENGTH temporal instants in which the node received acks.
double alpha_
Parameters used by Load metric.
double list_packets[LISTLENGTH]
List of the last LISTLENGTH temporal instants in which the node received data packets.
virtual const double getLoad() const
Returns the load index of the current node combining the information from getPacketsLastMinute() and ...
int pointer_acks_
Pointer of the first avaiable space in list_acks list.
bool acks_array_full
true if list of acks is full, false otherwise.
bool packets_array_full
true if list of packets is full, false otherwise.
#define STACK_TRACE
Used to keep track of methods call.
Dinamic source routing protocol, this file contains Nodes specifications.