Statistics
| Branch: | Revision:

streamers / measures.c @ 598b51d8

History | View | Annotate | Download (6.42 KB)

1
#include <mon.h>
2
#include <ml.h>
3

    
4
#include "dbg.h"
5
#include <net_helper.h>
6

    
7
static const char* channel = "OfferStreamer2";
8

    
9
typedef struct nodeID {
10
        socketID_handle addr;
11
        int connID;        // connection associated to this node, -1 if myself
12
        int refcnt;
13
        //a quick and dirty static vector for measures TODO: make it dinamic
14
        MonHandler mhs[20];
15
        int n_mhs;
16
} nodeID;
17

    
18
static MonHandler chunk_dup, chunk_playout, neigh_size;
19
static MonHandler rx_bytes_chunk_per_sec, tx_bytes_chunk_per_sec, rx_bytes_sig_per_sec, tx_bytes_sig_per_sec;
20
static MonHandler rx_chunks, tx_chunks;
21

    
22
/*
23
 * Initialize one measure
24
*/
25
void add_measure(MonHandler *mh, MeasurementId id, MeasurementCapabilities mc, MonParameterValue rate, const char *pubname, enum stat_types st[], int length, SocketId dst, MsgType mt)
26
{
27
        *mh = monCreateMeasure(id, mc);
28
        monSetParameter (*mh, P_PUBLISHING_RATE, rate);
29
        monPublishStatisticalType(*mh, pubname, channel, st , length, NULL);
30
        monActivateMeasure(*mh, dst, mt);
31
}
32

    
33
/*
34
 * Register duplicate arrival
35
*/
36
void reg_chunk_duplicate()
37
{
38
        if (!chunk_dup) {
39
                enum stat_types st[] = {SUM};
40
                add_measure(&chunk_dup, GENERIC, 0, 120, "ChunkDuplicates", st, sizeof(st)/sizeof(enum stat_types), NULL, MSG_TYPE_ANY);        //[chunks]
41
        }
42
        monNewSample(chunk_dup, 1);
43
}
44

    
45
/*
46
 * Register playout/loss of a chunk before playout
47
*/
48
void reg_chunk_playout(bool b)
49
{
50
        if (!chunk_playout && b) {        //don't count losses before the first arrived chunk
51
                enum stat_types st[] = {AVG, SUM};
52
                add_measure(&chunk_playout, GENERIC, 0, 120, "ChunksPlayed", st, sizeof(st)/sizeof(enum stat_types), NULL, MSG_TYPE_ANY);        //[chunks]
53
        }
54
        monNewSample(chunk_playout, b);
55
}
56

    
57
/*
58
 * Register actual neghbourhood size
59
*/
60
void reg_neigh_size(int s)
61
{
62
        if (!neigh_size) {
63
                enum stat_types st[] = {LAST};
64
                add_measure(&neigh_size, GENERIC, 0, 120, "NeighSize", st, sizeof(st)/sizeof(enum stat_types), NULL, MSG_TYPE_ANY);        //[peers]
65
        }
66
        monNewSample(neigh_size, s);
67
}
68

    
69
/*
70
 * Initialize peer level measurements
71
*/
72
void init_measures()
73
{
74
        enum stat_types stavg[] = {AVG, WIN_AVG};
75
        enum stat_types stsum[] = {SUM};
76

    
77
        // Traffic
78
       add_measure(&rx_bytes_chunk_per_sec, BULK_TRANSFER, RXONLY | PACKET | TIMER_BASED, 120, "RxBytesChunkPSec", stavg, sizeof(stavg)/sizeof(enum stat_types), NULL, MSG_TYPE_CHUNK);        //[bytes/s]
79
       add_measure(&tx_bytes_chunk_per_sec, BULK_TRANSFER, TXONLY | PACKET | TIMER_BASED, 120, "TxBytesChunkPSec", stavg, sizeof(stavg)/sizeof(enum stat_types), NULL, MSG_TYPE_CHUNK);        //[bytes/s]
80
       add_measure(&rx_bytes_sig_per_sec, BULK_TRANSFER, RXONLY | PACKET | TIMER_BASED, 120, "RxBytesSigPSec", stavg, sizeof(stavg)/sizeof(enum stat_types), NULL, MSG_TYPE_SIGNALLING);        //[bytes/s]
81
       add_measure(&tx_bytes_sig_per_sec, BULK_TRANSFER, TXONLY | PACKET | TIMER_BASED, 120, "TxBytesSigPSec", stavg, sizeof(stavg)/sizeof(enum stat_types), NULL, MSG_TYPE_SIGNALLING);        //[bytes/s]
82

    
83
        // Chunks
84
       add_measure(&rx_chunks, COUNTER, RXONLY | DATA | IN_BAND, 120, "RxChunks", stsum, sizeof(stsum)/sizeof(enum stat_types), NULL, MSG_TYPE_CHUNK);        //[chunks]
85
       add_measure(&tx_chunks, COUNTER, TXONLY | DATA | IN_BAND, 120, "TxChunks", stsum, sizeof(stsum)/sizeof(enum stat_types), NULL, MSG_TYPE_CHUNK);        //[chunks]
86
}
87

    
88
/*
89
 * Initialize p2p measurements towards a peer
90
*/
91
void add_measures(struct nodeID *id)
92
{
93
        // Add measures
94
        int j = 0;
95
        enum stat_types stavg[] = {AVG, WIN_AVG};
96
        enum stat_types stsum[] = {SUM};
97

    
98
        dprintf("adding measures to %s\n",node_addr(id));
99

    
100
        /* HopCount */
101
       add_measure(&id->mhs[j++], HOPCOUNT, TXRXUNI | PACKET | IN_BAND, 600, "HopCount", stavg, sizeof(stavg)/sizeof(enum stat_types), id->addr, MSG_TYPE_CHUNK);        //[IP hops]
102

    
103
        /* Round Trip Time */
104
       add_measure(&id->mhs[j++], RTT, TXRXBI | PACKET | IN_BAND, 60, "RoundTripDelay", stavg, sizeof(stavg)/sizeof(enum stat_types), id->addr, MSG_TYPE_SIGNALLING);        //[seconds]
105

    
106
        /* Loss */
107
       add_measure(&id->mhs[j++], LOSS, TXRXUNI | PACKET | IN_BAND, 60, "LossRate", stavg, sizeof(stavg)/sizeof(enum stat_types), id->addr, MSG_TYPE_CHUNK);        //[probability 0..1]
108

    
109
        // Cumulative Traffic
110
       //add_measure(&id->mhs[j++], BYTE, RXONLY | PACKET | IN_BAND, 120, "RxBytes", stsum, sizeof(stsum)/sizeof(enum stat_types), id->addr, MSG_TYPE_ANY);
111
       //add_measure(&id->mhs[j++], BYTE, TXONLY | PACKET | IN_BAND, 120, "TxBytes", stsum, sizeof(stsum)/sizeof(enum stat_types), id->addr, MSG_TYPE_ANY);
112
       add_measure(&id->mhs[j++], BYTE, RXONLY | PACKET | IN_BAND, 120, "RxBytesChunk", stsum, sizeof(stsum)/sizeof(enum stat_types), id->addr, MSG_TYPE_CHUNK);        //[bytes]
113
       add_measure(&id->mhs[j++], BYTE, TXONLY | PACKET | IN_BAND, 120, "TxBytesChunk", stsum, sizeof(stsum)/sizeof(enum stat_types), id->addr, MSG_TYPE_CHUNK);        //[bytes]
114

    
115
        // Traffic
116
       add_measure(&id->mhs[j++], BULK_TRANSFER, RXONLY | PACKET | TIMER_BASED, 120, "RxBytesChunkPSec", stavg, sizeof(stavg)/sizeof(enum stat_types), id->addr, MSG_TYPE_CHUNK);        //[bytes/s]
117
       add_measure(&id->mhs[j++], BULK_TRANSFER, TXONLY | PACKET | TIMER_BASED, 120, "TxBytesChunkPSec", stavg, sizeof(stavg)/sizeof(enum stat_types), id->addr, MSG_TYPE_CHUNK);        //[bytes/s]
118
       add_measure(&id->mhs[j++], BULK_TRANSFER, RXONLY | PACKET | TIMER_BASED, 120, "RxBytesSigPSec", stavg, sizeof(stavg)/sizeof(enum stat_types), id->addr, MSG_TYPE_SIGNALLING);        //[bytes/s]
119
       add_measure(&id->mhs[j++], BULK_TRANSFER, TXONLY | PACKET | TIMER_BASED, 120, "TxBytesSigPSec", stavg, sizeof(stavg)/sizeof(enum stat_types), id->addr, MSG_TYPE_SIGNALLING);        //[bytes/s]
120

    
121
        // Chunks
122
       add_measure(&id->mhs[j++], COUNTER, RXONLY | DATA | IN_BAND, 120, "RxChunks", stsum, sizeof(stsum)/sizeof(enum stat_types), id->addr, MSG_TYPE_CHUNK);        //[chunks]
123
       add_measure(&id->mhs[j++], COUNTER, TXONLY | DATA | IN_BAND, 120, "TxChunks", stsum, sizeof(stsum)/sizeof(enum stat_types), id->addr, MSG_TYPE_CHUNK);        //[chunks]
124

    
125
        // for static must not be more then 10 or whatever size is in net_helper-ml.c
126
        id->n_mhs = j;
127
}
128

    
129
/*
130
 * Delete p2p measurements towards a peer
131
*/
132
void delete_measures(struct nodeID *id)
133
{
134
        int j;
135
        dprintf("deleting measures from %s\n",node_addr(id));
136
        for(j = 0; j < id->n_mhs; j++) {
137
                monDestroyMeasure(id->mhs[j]);
138
        }
139
}
140

    
141
/*
142
 * Helper to retrieve a measure
143
*/
144
double get_measure(struct nodeID *id, int j, enum stat_types st)
145
{
146
        return monRetrieveResult(id->mhs[j], st);
147
}
148

    
149
/*
150
 * RTT to a given peer in seconds
151
*/
152
double get_rtt(struct nodeID *id){
153
        return get_measure(id, 1, WIN_AVG);
154
}
155

    
156
/*
157
 * loss ratio from a given peer as 0..1
158
*/
159
double get_lossrate(struct nodeID *id){
160
        return get_measure(id, 2, WIN_AVG);
161
}