Revision d1e0f2ca monl/measure_dispatcher.h

View differences:

monl/measure_dispatcher.h
44 44

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

  
47
/* DestinationId Comparison function */
48
//TODO change it to a correct implemnetation
49
// struct socketIdCompare
50
// {
51
// 	bool operator()(const SocketId x, const SocketId y) const { 
52
// 		char *xptr, *yptr;
53
// 		xptr = (char *) x;
54
// 		yptr = (char *) y;
55
// 		if(memcmp(xptr, yptr, SOCKETID_SIZE) == 0)
56
// 			return true;
57
// 		return false;
58
// 	}
59
// };
60
struct socketIdCompare
47
struct SocketIdMt {
48
	SocketId sid;
49
	MsgType mt;
50
};
51

  
52
struct socketIdMtCompare
61 53
{
62
	bool operator()(const SocketId x, const SocketId y) const { 
63
		if(mlCompareSocketIDs(x,y) == 0)
54
	bool operator()(struct SocketIdMt x, struct SocketIdMt y) const {
55
		if(mlCompareSocketIDs(x.sid,y.sid) == 0 && x.mt == y.mt)
64 56
			return true;
65 57
		return false;
66 58
	}
67 59
};
68
/* DestinationId Hash function */
69
// struct socketIdHash
70
// {
71
// 	int operator()(const SocketId x) const {
72
// 		uint32_t hash_code = 0;
73
// 		uint32_t *intptr = (uint32_t*) x;
74
// 		for(int i=0; i < SOCKETID_SIZE / sizeof(uint32_t); i++)
75
// 			hash_code = hash_code + intptr[i];
76
// 		return hash_code;
77
// 	}
78
// };
79
struct socketIdHash
60

  
61
struct socketIdMtHash
80 62
{
81
	int operator()(const SocketId x) const {
82
		return mlHashSocketID(x);
63
	int operator()(struct SocketIdMt x) const {
64
		return mlHashSocketID(x.sid) + x.mt;
83 65
	}
84 66
};
85 67

  
86 68
typedef struct {
87
	ExecutionList el_local;
88
	ExecutionList el_remote;
89
	// elements in the execution list
90
	int32_t n_el_local;
91
	int32_t n_el_remote;
92
} DestinationMsgTypeData;
93

  
94
struct pkt_result{
95
	result r_rx_local[R_LAST_PKT];
96
	result r_rx_remote[R_LAST_PKT];
97
	result r_tx_local[R_LAST_PKT];
98
	result r_tx_remote[R_LAST_PKT];
99
	uint32_t tx_seq_num;
100
	//TODO store here destination specific data
101
};
102

  
103
struct data_result {
104
	result r_rx_local[R_LAST_DATA];
105
	result r_rx_remote[R_LAST_DATA];
106
	result r_tx_local[R_LAST_DATA];
107
	result r_tx_remote[R_LAST_DATA];
108
	uint32_t tx_seq_num;
109
	//TODO store here destination specific data
110
};
111

  
112

  
113
typedef std::tr1::unordered_map<MsgType,struct pkt_result *> ResultPktListMsgType;
114
typedef std::tr1::unordered_map<MsgType,struct data_result *> ResultDataListMsgType;
115
typedef std::tr1::unordered_map<MsgType,DestinationMsgTypeData*> DispatcherListMsgType;
116

  
117
typedef struct {
118
	DispatcherListMsgType rx_pkt;
119
	DispatcherListMsgType tx_pkt;
120
	DispatcherListMsgType rx_data;
121
	DispatcherListMsgType tx_data;
122

  
123
	ResultPktListMsgType r_pkt;
124
	ResultDataListMsgType r_data;
125

  
126
	char *sid;
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;
127 93

  
128
} DestinationSocketIdData;
94
	ExecutionList mids_local;
95
	ExecutionList mids_remote;
96
} DestinationSocketIdMtData;
129 97

  
130
typedef std::tr1::unordered_map<SocketId,DestinationSocketIdData*,socketIdHash,socketIdCompare> DispatcherListSocketId;
131 98

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

  
133 101
class MeasureDispatcher {
134 102

  
135 103
	/* Execution lists for the message layer hooks */
136
	DispatcherListSocketId dispatcherList;
104
	DispatcherListSocketIdMt dispatcherList;
137 105
	
138
	int addMeasureToExecList(DispatcherListMsgType &dl, class MonMeasure *m, MsgType mt);
139
	int delMeasureFromExecList(DispatcherListMsgType &dl, class MonMeasure *m, MsgType mt);
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);
140 112

  
141
	class MonMeasure* findDep(DispatcherListMsgType &dl, MeasurementCapabilities flags, MsgType mt, MeasurementId mid);
142
	class MonMeasure* findMeasureFromId(DestinationSocketIdData *dsid, MeasurementCapabilities flags, MeasurementId mid, MsgType mt);
143
	int checkDeps(DestinationSocketIdData *dsid, MeasurementCapabilities flags, MeasurementId mid, MsgType mt);
113
	class MonMeasure* findMeasureFromId(DestinationSocketIdMtData *dd, MeasurementCapabilities flags, MeasurementId mid);
144 114

  
145 115
	int sendCtrlMsg(SocketId dst, Buffer &buffer);
146 116
	int receiveCtrlMsg(SocketId sid, MsgType mt, char *cbuf, int length);
......
176 146
			initial_ttl = 0;
177 147
	};
178 148

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

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

Also available in: Unified diff