Statistics
| Branch: | Revision:

grapes / include / scheduler_la.h @ ce1abd38

History | View | Annotate | Download (7.61 KB)

1
#ifndef SCHEDULER_LA_H
2
#define SCHEDULER_LA_H
3

    
4
#include "scheduler_common.h"
5

    
6
/** @file scheduler_la.h
7
  @brief Low level scheduling functions for chunk and peer selection.
8

9
  The interface contains highly customizable selector functions. Customization is supported along the following concepts:
10
        -# evaluator functions: selector functions can be parameterized by evaluator functions.
11
                By using evaluator functions, the decision process can be decoupled into two parts:
12
                -# a generic selector function operating on abstract peer and chunk weights
13
                -# the evaluator function linking the decision process to the peer's knowledge about other peers and chunks
14
        -# selection policy: ChunkFirst, PeerFirst, Composed and Hybrid selection policies are supported
15
        -# ordering method: two kinds of ordering methods are supported:
16
                -# Best: strict ordering accorging to the given evaluator functions
17
                -# Weighted: Weighted random selection accorging to the given weight functions
18
        -# filter functions: selections are typically filtered by functions such as whether a given peer (according to local knowledge) needs a given chunk.
19
                The abstraction of the filter concept allows for easy modification of these filter conditions.
20
*/
21

    
22
/**
23
  * Scheduler ordering methods
24
  */
25
typedef enum {SCHED_BEST,SCHED_WEIGHTED} SchedOrdering;
26

    
27
/**
28
  * @brief Prototype for filter functions that select useful peer-chunk combinations
29
  * @return true if the combination is valid, false otherwise
30
  */
31
typedef int (*filterFunction)(schedPeerID ,schedChunkID );
32

    
33
/**
34
  * @brief Prototype for function assigning a weigth to a peer
35
  * @return the weight associated to the peer
36
  */
37
typedef double (*peerEvaluateFunction)(schedPeerID*);
38

    
39
/**
40
  * @brief Prototype for function assigning a weigth to a given chunk
41
  * @return the weight associated to the chunk
42
  */
43
typedef double (*chunkEvaluateFunction)(schedChunkID*);
44

    
45
/**
46
  * @brief Prototype for function assigning a weigth to a peer-chunk pair
47
  * @return the weight associated to the peer-chunk pair
48
  */
49
typedef double (*pairEvaluateFunction)(struct PeerChunk*);
50

    
51
/**
52
  * @brief Prototype for a two operand double function used to combine weights
53
  */
54
typedef double (*double2op)(double,double);
55

    
56

    
57

    
58
/**
59
  @brief Low level scheduler function for selecting peers.
60

61
  If called with chunks_len=0, it will not consider chunks in the selection.
62
  Otherwise, if chunks_len>0, only those peers will be selected that could be interesting for at least one of the given chunks.
63

64
  @param [in] ordering the ordering method to be used
65
  @param [in] peers list of peers to select from
66
  @param [in] peers_len length of peers list
67
  @param [in] chunk list of chunks to select from
68
  @param [in] chunks_len length of chunks list
69
  @param [out] selected list of peers selected by the function
70
  @param [in,out] selected_len in: maximum number of peers to select; out: number of peers selected
71
  @param [in] filter only peers that satisfy the filter condition can be selected
72
  @param [in] peerevaluate peers are selected based on the weight assigned by this evaluator function
73
 */
74
void schedSelectPeers(SchedOrdering ordering, schedPeerID  *peers, int peers_len, schedChunkID  *chunks, int chunks_len,         //in
75
                     schedPeerID  *selected, int *selected_len,        //out, inout
76
                     filterFunction filter,
77
                     peerEvaluateFunction peerevaluate);
78

    
79
/**
80
  @brief Low level scheduler function for selecting chunks.
81

82
  If called with peers_len=0, it will not consider peers in the selection.
83
  Otherwise, if peers_len>0, only those chunks will be selected that could be interesting for at least one of the given peers.
84

85
 */
86
void schedSelectChunks(SchedOrdering ordering, schedPeerID  *peers, int peers_len, schedChunkID  *chunks, int chunks_len,         //in
87
                     schedChunkID  *selected, int *selected_len,        //out, inout
88
                     filterFunction filter,
89
                     chunkEvaluateFunction chunkevaluate);
90

    
91
/*---PeerFirst----------------*/
92

    
93
/**
94
  @brief Low level scheduler function for selecting peer-chunk pairs in chunk first order.
95

96
  First a peer is selected based on weights assigned by the peerevaluate function.
97
  Then, maximum selected_len chunks are selected for the given peer based on weights assigned by the chunkevaluate function.
98
  */
99
void schedSelectPeerFirst(SchedOrdering ordering, schedPeerID  *peers, size_t peers_len, schedChunkID  *chunks, size_t chunks_len,         //in
100
                     struct PeerChunk *selected, size_t *selected_len,        //out, inout
101
                     filterFunction filter,
102
                     peerEvaluateFunction peerevaluate, chunkEvaluateFunction chunkevaluate);
103

    
104
/*---ChunkFirst----------------*/
105

    
106
/**
107
  * @brief Low level scheduler function for selecting peer-chunk pairs in peer first order.
108

109
  First a chunk is selected based on weights assigned by the chunkevaluate function.
110
  Then, maximum selected_len peers are selected for the given chunk based on weights assigned by the peerevaluate function.
111
  */
112
void schedSelectChunkFirst(SchedOrdering ordering, schedPeerID  *peers, size_t peers_len, schedChunkID  *chunks, size_t chunks_len,         //in
113
                     struct PeerChunk *selected, size_t *selected_len,        //out, inout
114
                     filterFunction filter,
115
                     peerEvaluateFunction peerevaluate, chunkEvaluateFunction chunkevaluate);
116

    
117
/*---Composed----------------*/
118

    
119
/**
120
  * @brief Low level scheduler function for selecting peer-chunk pairs based on a composed evaluation function.
121

122
  A maximum of selected_len peer-chunk pairs are selected based on a composed weight function.
123
  @param [in] chunkevaluate function to assign a weight to each chunk
124
  @param [in] peerevaluate function to assign a weight to each peer
125
  @param [in] weightcombine operation to combine peer and chunk weight into one weight
126
  */
127
void schedSelectComposed(SchedOrdering ordering, schedPeerID  *peers, size_t peers_len, schedChunkID  *chunks, size_t chunks_len,         //in
128
                     struct PeerChunk *selected, size_t *selected_len,        //out, inout
129
                     filterFunction filter,
130
                     peerEvaluateFunction peerevaluate, chunkEvaluateFunction chunkevaluate, double2op weightcombine);
131

    
132
/*---PeersForChunks----------------*/
133
/** 
134
  * @brief Added by Arpad without knowing what he is doing
135
   Documentation: see above
136

137
  */
138
void schedSelectPeersForChunks(SchedOrdering ordering, schedPeerID *peers, size_t peers_len, schedChunkID *chunks, size_t chunks_len,        //in
139
                     schedPeerID *selected, size_t *selected_len,       //out, inout
140
                     filterFunction filter,
141
                     peerEvaluateFunction evaluate);
142

    
143
/*---Hybrid----------------*/
144

    
145
/**
146
  * @brief Low level scheduler function for selecting peer-chunk pairs based on a hybrid evaluation function.
147

148
  A maximum of selected_len peer-chunk pairs are selected based on the given evaluation function.
149
  @param [in] pairevaluate function to assign a weight to each peer-chunk pair
150
  */
151
void schedSelectHybrid(SchedOrdering ordering, schedPeerID  *peers, size_t peers_len, schedChunkID  *chunks, size_t chunks_len,         //in
152
                     struct PeerChunk *selected, size_t *selected_len,        //out, inout
153
                     filterFunction filter,
154
                     pairEvaluateFunction pairevaluate);
155

    
156

    
157
/*---selector function----------------*/
158
/**
159
  * casted evaluator for generic use in generic selector functions
160
  */
161
typedef double (*evaluateFunction)(void*);
162

    
163
/**
164
  * Select best N of K with the given ordering method
165
  */
166
void selectWithOrdering(SchedOrdering ordering, size_t size, unsigned char *base, size_t nmemb, double(*evaluate)(void *), unsigned char *selected,size_t *selected_len);
167

    
168
#endif /* SCHEDULER_LA_H */