00001 // Copyright (C) 2009 Institut fuer Telematik, Universitaet Karlsruhe (TH) 00002 // 00003 // This program is free software; you can redistribute it and/or 00004 // modify it under the terms of the GNU General Public License 00005 // as published by the Free Software Foundation; either version 2 00006 // of the License, or (at your option) any later version. 00007 // 00008 // This program is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 // GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License 00014 // along with this program; if not, write to the Free Software 00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00016 // 00017 00024 #include <cfloat> 00025 00026 #include <NeighborCache.h> 00027 00028 #include "SVivaldi.h" 00029 00030 00031 void SVivaldi::init(NeighborCache* neighborCache) 00032 { 00033 Vivaldi::init(neighborCache); 00034 00035 lossC = neighborCache->par("vivaldiLossConst"); 00036 lossResetLimit = neighborCache->par("lossResetLimit"); 00037 00038 loss = 0; 00039 WATCH(loss); 00040 } 00041 00042 00043 double SVivaldi::calcError(const simtime_t& rtt, double dist, double weight) 00044 { 00045 // get avg absolute prediction error 00046 double sum = neighborCache->getAvgAbsPredictionError(); 00047 00048 // update weighted moving average of local error 00049 return (sum * errorC) + ownCoords->getError() * (1 - errorC); 00050 } 00051 00052 00053 double SVivaldi::calcDelta(const simtime_t& rtt, double dist, double weight) 00054 { 00055 // calculate loss factor 00056 loss = lossC + (1 - lossC) * loss; 00057 if(fabs(dist - SIMTIME_DBL(rtt)) > lossResetLimit) loss = 0.0; 00058 00059 return coordC * weight * (1 - loss); 00060 }