+/*!
+ * @file frescan_bwres_analysis.h
+ *
+ * @brief FRESCAN bandwith reservation layer: mode change protocol
+ *
+ * @version 0.02
+ *
+ * @date 19-Jul-2008
+ *
+ * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
+ *
+ * @comments
+ *
+ * This module contains the mode change protocol
+ *
+ * @license
+ *
+ * -----------------------------------------------------------------------
+ * Copyright (C) 2006 - 2008 FRESCOR consortium partners:
+ *
+ * Universidad de Cantabria, SPAIN
+ * University of York, UK
+ * Scuola Superiore Sant'Anna, ITALY
+ * Kaiserslautern University, GERMANY
+ * Univ. Politécnica Valencia, SPAIN
+ * Czech Technical University in Prague, CZECH REPUBLIC
+ * ENEA SWEDEN
+ * Thales Communication S.A. FRANCE
+ * Visual Tools S.A. SPAIN
+ * Rapita Systems Ltd UK
+ * Evidence ITALY
+ *
+ * See http://www.frescor.org for a link to partners' websites
+ *
+ * FRESCOR project (FP6/2005/IST/5-034026) is funded
+ * in part by the European Union Sixth Framework Programme
+ * The European Union is not liable of any use that may be
+ * made of this code.
+ *
+ * This file is part of FRESCAN
+ *
+ * FRESCAN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * FRESCAN is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * distributed with FRESCAN; see file COPYING. If not, write to the
+ * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * As a special exception, including FRESCAN header files in a file,
+ * instantiating FRESCAN generics or templates, or linking other files
+ * with FRESCAN objects to produce an executable application, does not
+ * by itself cause the resulting executable application to be covered
+ * by the GNU General Public License. This exception does not
+ * however invalidate any other reasons why the executable file might be
+ * covered by the GNU Public License.
+ * -----------------------------------------------------------------------
+ *
+ */
+
+#include "frescan_bwres_mode_change.h"
+#include "frescan_data.h"
+#include <misc/linux_list.h>
+
+/**
+ * frescan_bwres_mode_change_protocol() - performs the mode change
+ *
+ * Follow the mode change protocol described in the paper.
+ *
+ */
+
+int frescan_bwres_mode_change_protocol(frescan_request_data_t *req_data)
+{
+ int ret;
+ frescan_node_t node;
+ frescan_sa_vres_t *vres;
+ frsh_sa_vres_data_t *sa_vres_data;
+ frsh_sa_time_t max_period_in_budget_dec;
+ frsh_sa_time_t max_period_in_budget_inc;
+ frescan_request_data_t tmp_req_data;
+
+ for(node=0; node<FRESCAN_MX_NODES; node++) {
+ INIT_LIST_HEAD(&the_networks[req_data->net].
+ mode_change_budget_inc_list_head[node]);
+
+ INIT_LIST_HEAD(&the_networks[req_data->net].
+ mode_change_budget_dec_list_head[node]);
+ }
+
+ max_period_in_budget_dec = (frsh_sa_time_t)0;
+ max_period_in_budget_inc = (frsh_sa_time_t)0;
+
+ list_for_each_entry
+ (vres,
+ &the_networks[req_data->net].scenario.vres_head.list,
+ list)
+ {
+ sa_vres_data = &the_networks[req_data->net].
+ scenario.fsa_scenario.sa_vres_alloc
+ [vres->fsa_vres_global_id];
+
+ vres->mode_change_type = 0;
+
+ if (sa_vres_data->c > vres->old_c) {
+ vres->mode_change_type |= FRESCAN_SA_BUDGET_INC;
+
+ if (sa_vres_data->t > max_period_in_budget_inc) {
+ max_period_in_budget_inc = sa_vres_data->t;
+ }
+
+ list_add_tail
+ (&(vres->mode_change_list),
+ &(the_networks[req_data->net].
+ mode_change_budget_inc_list_head[vres->node]));
+ } else {
+ vres->mode_change_type |= FRESCAN_SA_BUDGET_DEC;
+
+ if (sa_vres_data->t > max_period_in_budget_dec) {
+ max_period_in_budget_dec = sa_vres_data->t;
+ }
+
+ list_add_tail
+ (&(vres->mode_change_list),
+ &(the_networks[req_data->net].
+ mode_change_budget_dec_list_head[vres->node]));
+ }
+
+ if (sa_vres_data->t > vres->old_t) {
+ vres->mode_change_type |= FRESCAN_SA_PERIOD_INC;
+ } else {
+ vres->mode_change_type |= FRESCAN_SA_PERIOD_DEC;
+ }
+
+ if (sa_vres_data->p > vres->old_p) {
+ vres->mode_change_type |= FRESCAN_SA_PRIO_INC;
+ } else {
+ vres->mode_change_type |= FRESCAN_SA_PRIO_DEC;
+ }
+
+ vres->old_c = sa_vres_data->c;
+ vres->old_t = sa_vres_data->t;
+ vres->old_p = sa_vres_data->p;
+ }
+
+ // mode change for B- members
+ for(node=FRESCAN_MX_NODES-1; node>=0; node--) {
+ list_for_each_entry(vres,
+ &the_networks[req_data->net].
+ mode_change_budget_dec_list_head[node],
+ mode_change_list)
+ {
+ if (node == FRESCAN_NEG_MASTER_NODE) {
+ // put the values
+ the_servers_pool[req_data->net][vres->ss].params = ...
+
+
+
+
+
+
+ } else {
+ if (req_data->request_node != FRESCAN_NEG_MASTER_NODE) {
+ DEBUG(FRESCAN_MANAGER_ENABLE_DEBUG,
+ "sending reply\n");
+ req_data->type = FRESCAN_REP_NEG;
+ ret = frescan_messages_send_request(req_data);
+ assert(ret == 0);
+ } else {
+ tmp_req_data.type = FRESCAN_REP_CHANGE;
+ tmp_req_data.node = ...;
+
+ ret = frescan_messages_send_request(&tmp_req_data);
+ if (ret != 0) return -1;
+ }
+ }
+ }
+
+ if (node == FRESCAN_NEG_MASTER_NODE) {
+ beginning = clock
+ // delay
+ clock_nanosleep(absolute, beginning+period
+ // commmit
+ list_del lo que ha disminuido
+ }
+ }
+
+ // wait the time needed to keep schedulability
+
+
+ // mode change for B+ members
+
+
+ return 0;
+}