]> rtime.felk.cvut.cz Git - frescor/fna.git/blob - src_frescan/frescan_bwres_mode_change.c
1d44ea1f02437dc3ab9d2dd8084fe1e3c76869d2
[frescor/fna.git] / src_frescan / frescan_bwres_mode_change.c
1 /*!
2  * @file frescan_bwres_analysis.h
3  *
4  * @brief FRESCAN bandwith reservation layer: mode change protocol
5  *
6  * @version 0.02
7  *
8  * @date 19-Jul-2008
9  *
10  * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
11  *
12  * @comments
13  *
14  * This module contains the mode change protocol
15  *
16  * @license
17  *
18  * -----------------------------------------------------------------------
19  *  Copyright (C) 2006 - 2008 FRESCOR consortium partners:
20  *
21  *    Universidad de Cantabria,              SPAIN
22  *    University of York,                    UK
23  *    Scuola Superiore Sant'Anna,            ITALY
24  *    Kaiserslautern University,             GERMANY
25  *    Univ. Politécnica  Valencia,           SPAIN
26  *    Czech Technical University in Prague,  CZECH REPUBLIC
27  *    ENEA                                   SWEDEN
28  *    Thales Communication S.A.              FRANCE
29  *    Visual Tools S.A.                      SPAIN
30  *    Rapita Systems Ltd                     UK
31  *    Evidence                               ITALY
32  *
33  *    See http://www.frescor.org for a link to partners' websites
34  *
35  *           FRESCOR project (FP6/2005/IST/5-034026) is funded
36  *        in part by the European Union Sixth Framework Programme
37  *        The European Union is not liable of any use that may be
38  *        made of this code.
39  *
40  *  This file is part of FRESCAN
41  *
42  *  FRESCAN is free software; you can  redistribute it and/or  modify
43  *  it under the terms of  the GNU General Public License as published by
44  *  the Free Software Foundation;  either  version 2, or (at  your option)
45  *  any later version.
46  *
47  *  FRESCAN  is distributed  in  the hope  that  it  will  be useful,  but
48  *  WITHOUT  ANY  WARRANTY;     without  even the   implied   warranty  of
49  *  MERCHANTABILITY  or  FITNESS FOR  A  PARTICULAR PURPOSE. See  the  GNU
50  *  General Public License for more details.
51  *
52  *  You should have  received a  copy of  the  GNU  General Public License
53  *  distributed  with  FRESCAN;  see file COPYING.   If not,  write to the
54  *  Free Software  Foundation,  59 Temple Place  -  Suite 330,  Boston, MA
55  *  02111-1307, USA.
56  *
57  * As a special exception, including FRESCAN header files in a file,
58  * instantiating FRESCAN generics or templates, or linking other files
59  * with FRESCAN objects to produce an executable application, does not
60  * by itself cause the resulting executable application to be covered
61  * by the GNU General Public License. This exception does not
62  * however invalidate any other reasons why the executable file might be
63  * covered by the GNU Public License.
64  * -----------------------------------------------------------------------
65  *
66  */
67
68 #include "frescan_bwres_mode_change.h"
69 #include "frescan_data.h"
70 #include <misc/linux_list.h>
71
72 /**
73  * frescan_bwres_mode_change_protocol() - performs the mode change
74  *
75  * Follow the mode change protocol described in the paper.
76  *
77  */
78
79 int frescan_bwres_mode_change_protocol(frescan_request_data_t *req_data)
80 {
81         int ret;
82         frescan_node_t node;
83         frescan_sa_vres_t *vres;
84         frsh_sa_vres_data_t *sa_vres_data;
85         frsh_sa_time_t max_period_in_budget_dec;
86         frsh_sa_time_t max_period_in_budget_inc;
87         frescan_request_data_t tmp_req_data;
88
89         for(node=0; node<FRESCAN_MX_NODES; node++) {
90                 INIT_LIST_HEAD(&the_networks[req_data->net].
91                                 mode_change_budget_inc_list_head[node]);
92
93                 INIT_LIST_HEAD(&the_networks[req_data->net].
94                                 mode_change_budget_dec_list_head[node]);
95         }
96
97         max_period_in_budget_dec = (frsh_sa_time_t)0;
98         max_period_in_budget_inc = (frsh_sa_time_t)0;
99
100         list_for_each_entry
101                         (vres,
102                          &the_networks[req_data->net].scenario.vres_head.list,
103                          list)
104         {
105                 sa_vres_data = &the_networks[req_data->net].
106                                 scenario.fsa_scenario.sa_vres_alloc
107                                                 [vres->fsa_vres_global_id];
108
109                 vres->mode_change_type = 0;
110
111                 if (sa_vres_data->c > vres->old_c) {
112                         vres->mode_change_type |= FRESCAN_SA_BUDGET_INC;
113
114                         if (sa_vres_data->t > max_period_in_budget_inc) {
115                                 max_period_in_budget_inc = sa_vres_data->t;
116                         }
117
118                         list_add_tail
119                             (&(vres->mode_change_list),
120                              &(the_networks[req_data->net].
121                                mode_change_budget_inc_list_head[vres->node]));
122                 } else {
123                         vres->mode_change_type |= FRESCAN_SA_BUDGET_DEC;
124
125                         if (sa_vres_data->t > max_period_in_budget_dec) {
126                                 max_period_in_budget_dec = sa_vres_data->t;
127                         }
128
129                         list_add_tail
130                             (&(vres->mode_change_list),
131                              &(the_networks[req_data->net].
132                                mode_change_budget_dec_list_head[vres->node]));
133                 }
134
135                 if (sa_vres_data->t > vres->old_t) {
136                         vres->mode_change_type |= FRESCAN_SA_PERIOD_INC;
137                 } else {
138                         vres->mode_change_type |= FRESCAN_SA_PERIOD_DEC;
139                 }
140
141                 if (sa_vres_data->p > vres->old_p) {
142                         vres->mode_change_type |= FRESCAN_SA_PRIO_INC;
143                 } else {
144                         vres->mode_change_type |= FRESCAN_SA_PRIO_DEC;
145                 }
146
147                 vres->old_c = sa_vres_data->c;
148                 vres->old_t = sa_vres_data->t;
149                 vres->old_p = sa_vres_data->p;
150         }
151
152         // mode change for B- members
153         for(node=0; node<FRESCAN_MX_NODES; node++) { // TODO: end with master
154                 list_for_each_entry(vres,
155                                     &the_networks[req_data->net].
156                                      mode_change_budget_dec_list_head[node],
157                                     mode_change_list)
158                 {
159                         if (node == FRESCAN_NEG_MASTER_NODE) {
160                                 // put the values
161                                 the_servers_pool[req_data->net][vres->ss].params = ...
162
163
164
165
166
167
168                         } else {
169                                 if (req_data->request_node != FRESCAN_NEG_MASTER_NODE) {
170                                         DEBUG(FRESCAN_MANAGER_ENABLE_DEBUG,
171                                               "sending reply\n");
172                                         req_data->type = FRESCAN_REP_NEG;
173                                         ret = frescan_messages_send_request(req_data);
174                                         assert(ret == 0);
175                                 } else {
176                                         tmp_req_data.type = FRESCAN_REP_CHANGE;
177                                         tmp_req_data.node = ...;
178
179                                         ret = frescan_messages_send_request(&tmp_req_data);
180                                         if (ret != 0) return -1;
181                                 }
182                         }
183                 }
184
185                 if (node == FRESCAN_NEG_MASTER_NODE) {
186                                 beginning = clock
187                                 // delay
188                                 clock_nanosleep(absolute, beginning+period
189                                 // commmit
190                                 list_del  lo que ha disminuido
191                 }
192         }
193
194         // wait the time needed to keep schedulability
195
196
197         // mode change for B+ members
198
199
200         return 0;
201 }