Statistics
| Branch: | Revision:

napa-baselibs / monl / measure_dispatcher.h @ d1e0f2ca

History | View | Annotate | Download (4.75 KB)

1
/***************************************************************************
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
#ifndef _MEASURE_DISPATCHER_H_
21
#define _MEASURE_DISPATCHER_H_
22

    
23
#include "mon_measure.h"
24
#include "measure_plugin.h"
25

    
26
#include <tr1/unordered_map>
27

    
28
//#include <iostream>
29

    
30
#include <vector>
31
#include <string.h>
32

    
33
#include "ml.h"
34

    
35
typedef std::vector<char> Buffer;
36

    
37
typedef struct {
38
        char *msg;
39
        int32_t length;
40
        char sid[SOCKETID_SIZE];
41
        MsgType mt;
42
        send_params sparam;
43
} Message;
44

    
45
void open_con_cb (int con_id, void *arg);
46

    
47
struct SocketIdMt {
48
        SocketId sid;
49
        MsgType mt;
50
};
51

    
52
struct socketIdMtCompare
53
{
54
        bool operator()(struct SocketIdMt x, struct SocketIdMt y) const {
55
                if(mlCompareSocketIDs(x.sid,y.sid) == 0 && x.mt == y.mt)
56
                        return true;
57
                return false;
58
        }
59
};
60

    
61
struct socketIdMtHash
62
{
63
        int operator()(struct SocketIdMt x) const {
64
                return mlHashSocketID(x.sid) + x.mt;
65
        }
66
};
67

    
68
typedef struct {
69
        ExecutionList el_rx_pkt_local;
70
        ExecutionList el_rx_pkt_remote;
71
        ExecutionList el_tx_pkt_local;
72
        ExecutionList el_tx_pkt_remote;
73
        ExecutionList el_rx_data_local;
74
        ExecutionList el_rx_data_remote;
75
        ExecutionList el_tx_data_local;
76
        ExecutionList el_tx_data_remote;
77

    
78
        result pkt_r_rx_local[R_LAST_PKT];
79
        result pkt_r_rx_remote[R_LAST_PKT];
80
        result pkt_r_tx_local[R_LAST_PKT];
81
        result pkt_r_tx_remote[R_LAST_PKT];
82
        uint32_t pkt_tx_seq_num;
83

    
84
        result data_r_rx_local[R_LAST_DATA];
85
        result data_r_rx_remote[R_LAST_DATA];
86
        result data_r_tx_local[R_LAST_DATA];
87
        result data_r_tx_remote[R_LAST_DATA];
88
        uint32_t data_tx_seq_num;
89

    
90
        uint8_t sid[SOCKETID_SIZE];
91
        MsgType mt;
92
        SocketIdMt h_dst;
93

    
94
        ExecutionList mids_local;
95
        ExecutionList mids_remote;
96
} DestinationSocketIdMtData;
97

    
98

    
99
typedef std::tr1::unordered_map<struct SocketIdMt, DestinationSocketIdMtData*, socketIdMtHash, socketIdMtCompare> DispatcherListSocketIdMt;
100

    
101
class MeasureDispatcher {
102

    
103
        /* Execution lists for the message layer hooks */
104
        DispatcherListSocketIdMt dispatcherList;
105
        
106
        void addMeasureToExecLists(SocketIdMt h_dst, class MonMeasure *m);
107
        void delMeasureFromExecLists(MonMeasure *m);
108
        int stopMeasure(class MonMeasure *m);
109

    
110
        void createDestinationSocketIdMtData(struct SocketIdMt h_dst);
111
        void destroyDestinationSocketIdMtData(SocketId dst, MsgType mt);
112

    
113
        class MonMeasure* findMeasureFromId(DestinationSocketIdMtData *dd, MeasurementCapabilities flags, MeasurementId mid);
114

    
115
        int sendCtrlMsg(SocketId dst, Buffer &buffer);
116
        int receiveCtrlMsg(SocketId sid, MsgType mt, char *cbuf, int length);
117

    
118
        int remoteMeasureResponseRx(SocketId src, MsgType mt, char* cbuf);
119
        int remoteMeasureResponseTx(SocketId dst, MonHandler mhr, MonHandler mh, int32_t cid, int32_t status);
120

    
121
        int remoteResultsTx(SocketId dst, struct res_mh_pair *rmp, int length, MsgType mt);
122
        int remoteResultsRx(SocketId src, MsgType mt, char *cbuf);
123

    
124
        int initRemoteMeasureTx(class MonMeasure *m, SocketId dst, MsgType mt);
125
        int initRemoteMeasureRx(SocketId src, MsgType mt, char *cbuf);
126

    
127
        int deinitRemoteMeasureTx(class MonMeasure *m);
128
        int deinitRemoteMeasureRx(SocketId src, MsgType mt, char* cbuff);
129

    
130
        int oobDataRx(SocketId sid, MsgType mt, char *cbuf, int length);
131

    
132
        void headerSetup(eControlId type, Buffer &msg);
133
protected:
134
        class MeasureManager *mm;
135

    
136
        uint8_t initial_ttl;
137

    
138
        friend class MeasureManager;
139
        friend class MonMeasure;
140
public:
141
        MeasureDispatcher(): initial_ttl(0) {
142
                int error1, error2;
143
                uint8_t ttl;
144
                error2 = mlGetStandardTTL(mlGetLocalSocketID(&error1), &initial_ttl);
145
                if(error1 == 1 || error2 != 1)
146
                        initial_ttl = 0;
147
        };
148

    
149
        int activateMeasure(class MonMeasure *m, SocketId dst, MsgType mt, int autoload = 1);
150
        int deactivateMeasure(class MonMeasure *m);
151

    
152
        int oobDataTx(class MonMeasure *m, char *buf, int buf_len);
153

    
154
        int scheduleMeasure(MonHandler mh);
155
        int schedulePublish(MonHandler mh);
156

    
157
        /* CAllback Functions */
158
        void cbRxPkt(void *arg);
159
        void cbRxData(void *arg);
160
        void cbTxPkt(void *arg);
161
        void cbTxData(void *arg);
162
        int cbHdrPkt(SocketId sid, MsgType mt);
163
        int cbHdrData(SocketId sid, MsgType mt);
164
};
165

    
166
#endif /* _MEASURE_DISPATCHER_H_ */