00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "logging-data-struct.h"
00038
00039
00040
00041
00042 LoggingDataStruct::LoggingDataStruct(Node * node, RouteLogic * rtLogic,
00043 int sampleAddress, double estimate) {
00044 first_ = NULL;
00045 count_=0;
00046 myID_ = node->nodeid();
00047 rateEstimator_ = new RateEstimator(estimate);
00048 reset_time_ = Scheduler::instance().clock();
00049 gotStatusAll_ = 0;
00050 statusArrivalRateAll_=-1;
00051 rtLogic_ = rtLogic;
00052
00053 neighbor_list_node * nextNode = node->neighbor_list_;
00054 while (nextNode != NULL) {
00055 int nid = nextNode->nodeid;
00056 int nextHopID = rtLogic_->lookup_flat(nid, sampleAddress);
00057 if (nextHopID == node->nodeid() ) {
00058 LoggingDataStructNode * lgdsNode = new LoggingDataStructNode(nid, first_);
00059 first_ = lgdsNode;
00060 count_++;
00061 }
00062 nextNode = nextNode->next;
00063 }
00064
00065 }
00066
00067 void
00068 LoggingDataStruct::log(Packet * pkt) {
00069
00070 rateEstimator_->estimateRate(pkt);
00071
00072 hdr_ip * iph = hdr_ip::access(pkt);
00073 ns_addr_t src = iph->src();
00074
00075
00076
00077
00078 int neighborID = rtLogic_->lookup_flat(myID_,src.addr_);
00079 #ifdef DEBUG_LGDS
00080 printf("LGDS: %d total = %g rate = %g src = %d neighnorID = %d\n", myID_,
00081 rateEstimator_->bytesArr_/500.0, rateEstimator_->estRate_, src.addr_, neighborID);
00082 #endif
00083
00084 if (neighborID == myID_) return;
00085
00086 LoggingDataStructNode * node = getNodeByID(neighborID);
00087 if (node == NULL) {
00088 #ifdef DEBUG_LGDS
00089 fprintf(stdout,"LGDS: %d neighbor not found in the struct !!\n", myID_);
00090 #endif
00091 return;
00092
00093 }
00094 node->log(pkt);
00095 }
00096
00097
00098
00099
00100 int
00101 LoggingDataStruct::consolidateStatus() {
00102
00103 double rate = 0;
00104 int all = 1;
00105 LoggingDataStructNode * node = first_;
00106 while (node != NULL) {
00107 if (!node->gotStatus_) {
00108 if (node->statusArrivalRate_<0) {
00109
00110 printf("LGDS: Error: This should never happen now\n");
00111 exit(-1);
00112
00113 }
00114 else {
00115 all = 0;
00116 }
00117 }
00118 rate += node->statusArrivalRate_;
00119 node = node->next_;
00120 }
00121
00122 gotStatusAll_ = all;
00123 statusArrivalRateAll_=rate;
00124
00125 return all;
00126 }
00127
00128 void
00129 LoggingDataStruct::resetStatus() {
00130 LoggingDataStructNode * node = first_;
00131 while (node != NULL) {
00132 node->gotStatus_=0;
00133 node = node->next_;
00134 }
00135 }
00136
00137 void
00138 LoggingDataStruct::registerStatus(int sender, double arrRate) {
00139
00140 LoggingDataStructNode * node = getNodeByID(sender);
00141
00142 if (node == NULL) {
00143 printf("LGDS: sender not in my list (status processing)\n");
00144 exit(-1);
00145 }
00146
00147 node->registerStatus(arrRate);
00148 }
00149
00150 LoggingDataStructNode *
00151 LoggingDataStruct::getNodeByID(int id) {
00152
00153 LoggingDataStructNode * node = first_;
00154 while (node != NULL) {
00155 if (node->nid_ == id) {
00156 return node;
00157 }
00158 node = node->next_;
00159 }
00160
00161 return NULL;
00162 }
00163
00164 LoggingDataStruct::~LoggingDataStruct() {
00165
00166 LoggingDataStructNode * node = first_;
00167 while (node!=NULL) {
00168 LoggingDataStructNode * next = node->next_;
00169 delete(node);
00170 node = next;
00171 }
00172
00173 delete(rateEstimator_);
00174 }
00175
00176
00177
00178 LoggingDataStructNode::LoggingDataStructNode(int id, LoggingDataStructNode * next) {
00179
00180
00181 nid_ = id;
00182 rateEstimator_ = new RateEstimator();
00183
00184 pushbackSent_ = 0;
00185 limit_ = -1;
00186 gotStatus_ = 0;
00187 statusArrivalRate_ = -1;
00188 countLessReportedRate_=0;
00189 sentRefresh_=0;
00190 next_ = next;
00191 }
00192
00193 void
00194 LoggingDataStructNode::pushbackSent(double limit, double expectedStatusRate) {
00195 pushbackSent_ = 1;
00196 limit_ = limit;
00197 statusArrivalRate_ = expectedStatusRate;
00198 }
00199
00200 void
00201 LoggingDataStructNode::sentRefresh(double limit) {
00202 sentRefresh_ = 1;
00203 limit_ = limit;
00204 }
00205
00206 void
00207 LoggingDataStructNode::registerStatus(double arrRate) {
00208 gotStatus_ = 1;
00209
00210
00211 if (limit_ < INFINITE_LIMIT - 1 ) {
00212 statusArrivalRate_ = arrRate;
00213 countLessReportedRate_=0;
00214 return;
00215 }
00216
00217 if (arrRate >= statusArrivalRate_) {
00218 statusArrivalRate_ = arrRate;
00219 countLessReportedRate_=0;
00220 return;
00221 } else {
00222 countLessReportedRate_++;
00223 if (countLessReportedRate_ > 1) {
00224 statusArrivalRate_=(arrRate+statusArrivalRate_)/2;
00225 return;
00226 }
00227 else {
00228
00229 }
00230 }
00231 }
00232
00233 void
00234 LoggingDataStructNode::log(Packet * pkt) {
00235 rateEstimator_->estimateRate(pkt);
00236 #ifdef DEBUG_LGDSN
00237 printf("LGDSN: for neighbor %d total = %g rate = %g \n", nid_,
00238 rateEstimator_->bytesArr_/500.0, rateEstimator_->estRate_);
00239 #endif
00240 }
00241
00242 LoggingDataStructNode::~LoggingDataStructNode() {
00243 delete(rateEstimator_);
00244 }