Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (3.16 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 "seqwin_measure.h"
21
22
SeqWinMeasure::SeqWinMeasure(class MeasurePlugin *m, MeasurementCapabilities mc, class MeasureDispatcher *md): MonMeasure(m,mc,md), win_valid(false),
23
                largest_sn(0), initial_sn(0)
24
{
25
        sn_win = new uint32_t[(int) param_values[P_SEQN_WIN_SIZE]];
26
}
27
28
SeqWinMeasure::~SeqWinMeasure() {
29
        delete[] sn_win;
30
}
31
32
int SeqWinMeasure::paramChange(MonParameterType ph, MonParameterValue p) {
33
        switch(ph) {
34
                case P_SEQN_WIN_SIZE:
35
                        delete[] sn_win;
36
                        sn_win = new uint32_t[(int) p];
37
                        //TODO: possibly improve to keep previous values
38
                        pnum = 0;
39
                        return EOK;
40
                default:
41
                        return EOK;
42
        }
43
}
44
45
void SeqWinMeasure::init() {
46
        pnum = 0;
47
}
48
49
void SeqWinMeasure::stop() {
50
        r_tx_list[R_SEQWIN] = r_rx_list[R_SEQWIN] = NAN;
51
}
52
53
result SeqWinMeasure::RxPkt(result *r, ExecutionList *el) {
54
        uint32_t ind;
55
        uint32_t delta_sn_win;
56
        uint32_t p_sn = (uint32_t)r[R_SEQNUM];
57
58
        //first packet?
59
        if(pnum == 0) {
60
                initial_sn = largest_sn = p_sn;
61
                //TODO: check this
62
                for(ind = 0; ind < (int) param_values[P_SEQN_WIN_SIZE]; ind++)
63
                        sn_win[ind] = p_sn;
64
                win_valid = false;
65
                pnum = 1;
66
                return NAN;
67
        }
68
69
        ind = p_sn - initial_sn;
70
        if(ind >= param_values[P_SEQN_WIN_SIZE])
71
                win_valid = true; //ew filled at least 1 window
72
        ind = ind % (uint32_t) param_values[P_SEQN_WIN_SIZE];
73
        delta_sn_win = p_sn - sn_win[ind];
74
75
        if(p_sn - largest_sn < param_values[P_SEQN_WIN_OVERFLOW_TH])
76
                largest_sn = p_sn;
77
78
        if(!win_valid) {
79
                sn_win[ind] = p_sn;
80
                //check for overflow (TODO: needed ? ask marco)
81
        } else if(delta_sn_win < param_values[P_SEQN_WIN_OVERFLOW_TH])
82
                sn_win[ind] = p_sn;
83
84
        if(delta_sn_win == 0)
85
                r[R_SEQWIN] = 0;
86
        else if(win_valid)
87
                r[R_SEQWIN] = delta_sn_win;
88
89 792465fa CsabaKiraly
        return NAN;
90 956892f0 ArpadBakay
}
91
92
result SeqWinMeasure::RxData(result *r, ExecutionList *el) {
93
        return RxPkt(r, el);
94
}
95
96
SeqWinMeasurePlugin::SeqWinMeasurePlugin() {
97
        /* Initialise properties: MANDATORY! */
98
        name = "Sequence Number Window";
99
        desc = "A sequence number window handler as support to loss, late, dup, burst measures";
100
        id = SEQWIN;
101
        /* end of mandatory properties */
102
        addParameter(new MinParameter ("SeqnumWinSize","Sequence number window size",1,5),P_SEQN_WIN_SIZE);
103
        addParameter(new MinParameter ("SeqnumWinOverflow","Sequence number window overflow detection threshold",1,500),P_SEQN_WIN_OVERFLOW_TH);
104
}
105
106