Statistics
| Branch: | Revision:

napa-baselibs / monl / plugins / hopcount_measure.cpp @ d2cfc5c9

History | View | Annotate | Download (2.04 KB)

1 956892f0 ArpadBakay
/***************************************************************************
2
 *   Copyright (C) 2009 by Robert Birke
3
 *   robert.birke@polito.it
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2.1 of the License, or (at your option) any later version.
9

10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
14

15
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA 
18
 ***********************************************************************/
19
20
#include "hopcount_measure.h"
21
22 d2cfc5c9 Csaba Kiraly
HopcountMeasure::HopcountMeasure(class MeasurePlugin *m, MeasurementCapabilities mc, class MeasureDispatcher *md): MonMeasure(m,mc,md,100) {
23 956892f0 ArpadBakay
};
24
25
HopcountMeasure::~HopcountMeasure() {
26
}
27
28
void HopcountMeasure::stop() {
29
        r_tx_list[R_HOPCOUNT] = r_rx_list[R_HOPCOUNT] = NAN;
30
}
31
32
result HopcountMeasure::RxPkt(result *r,ExecutionList *el) {
33
        if(r[R_INITIAL_TTL] != 0.0 && !isnan(r[R_INITIAL_TTL]))
34
                r[R_HOPCOUNT] = r[R_INITIAL_TTL]-r[R_TTL];
35
        else {
36
                //use heuristic
37
                if(r[R_TTL] <= 32)
38
                        r[R_HOPCOUNT] = 32 - r[R_TTL];
39
                else if(r[R_TTL] <= 64)
40
                        r[R_HOPCOUNT] = 64 - r[R_TTL];
41
                else if(r[R_TTL] <= 128)
42
                        r[R_HOPCOUNT] = 128 - r[R_TTL];
43
                else
44
                        r[R_HOPCOUNT] = 256 - r[R_TTL];
45
        }
46
        char dbg[512];
47
        snprintf(dbg, sizeof(dbg), "Ts: %f Hops: %f (%f-%f)", r[R_SEND_TIME], r[R_HOPCOUNT], r[R_TTL], r[R_INITIAL_TTL]);
48
        debugOutput(dbg);
49 792465fa CsabaKiraly
        return every(r[R_HOPCOUNT]);
50 956892f0 ArpadBakay
}
51
52
HopcountMeasurePlugin::HopcountMeasurePlugin() {
53
        /* Initialise properties: MANDATORY! */
54
        name = "Hopcount";
55
        desc = "The distance between two peers in terms of hopcount";
56
        id = HOPCOUNT;
57
        /* end of mandatory properties */
58
}