Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

logging-data-struct.cc

Go to the documentation of this file.
00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 /*
00003  * Copyright (c) 2000  International Computer Science Institute
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 3. All advertising materials mentioning features or use of this software
00015  *    must display the following acknowledgement:
00016  *      This product includes software developed by ACIRI, the AT&T 
00017  *      Center for Internet Research at ICSI (the International Computer
00018  *      Science Institute).
00019  * 4. Neither the name of ACIRI nor of ICSI may be used
00020  *    to endorse or promote products derived from this software without
00021  *    specific prior written permission.
00022  *
00023  * THIS SOFTWARE IS PROVIDED BY ICSI AND CONTRIBUTORS ``AS IS'' AND
00024  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026  * ARE DISCLAIMED.  IN NO EVENT SHALL ICSI OR CONTRIBUTORS BE LIABLE
00027  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00028  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00029  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00032  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00033  * SUCH DAMAGE.
00034  *
00035  */
00036 
00037 #include "logging-data-struct.h"
00038 
00039 
00040 // ########################## LoggingDataStruct Methods ####################
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() /*|| AGGREGATE_CLASSIFICATION_MODE_FID == 1*/) {
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   // there is a symmetry of routing assumption built into this computation.
00076   // if it does not hold, we need some explicit support to know 
00077   // which neighbor sent us this packet
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     //exit(-1);
00093   }
00094   node->log(pkt);
00095 }
00096 
00097 //return -1 if not received status from a neighbor even once.
00098 //return 0 if not received status from a neighbor in this round.
00099 //return 1 o/w.  
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         //condition 1 above.
00110         printf("LGDS: Error: This should never happen now\n");
00111         exit(-1);
00112         //return -1;
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 // ########################## LoggingDataStructNode Methods ####################
00177 
00178 LoggingDataStructNode::LoggingDataStructNode(int id, LoggingDataStructNode * next) {
00179   
00180   //printf("LGDSN: Setting up node for %d\n", id);
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   //not doing precise math for floating imprecision
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       //keep the old rate
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 }

Generated on Tue Apr 20 12:14:22 2004 for NS2.26SourcesOriginal by doxygen 1.3.3