Subversion Repositories shark

Rev

Rev 679 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
668 trimarchi 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Trimarchi Michael   <trimarchi@gandalf.sssup.it>
10
 *   (see the web pages for full authors list)
11
 *
12
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
13
 *
14
 * http://www.sssup.it
15
 * http://retis.sssup.it
16
 * http://shark.sssup.it
17
 */
18
 
19
/*
20
 * Copyright (C) 2000 Giorgio Buttazzo, Paolo Gai
21
 *
22
 * This program is free software; you can redistribute it and/or modify
23
 * it under the terms of the GNU General Public License as published by
24
 * the Free Software Foundation; either version 2 of the License, or
25
 * (at your option) any later version.
26
 *
27
 * This program is distributed in the hope that it will be useful,
28
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30
 * GNU General Public License for more details.
31
 *
32
 * You should have received a copy of the GNU General Public License
33
 * along with this program; if not, write to the Free Software
34
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
35
 *
36
 *
37
 * CVS :        $Id: server-task.c,v 1.1 2004-05-20 12:13:55 trimarchi Exp $
38
 */
39
 
40
#include <kernel/kern.h>
41
#include <modules/cabs.h>
42
#include <string.h>
43
#include "message.h"
44
 
45
 
46
 
47
char    *mchannel[2]={"MCHANR","MCHANW"};
48
CAB     mchannelid[2];
49
 
50
TASK    service_task(void *arg) {
51
 
52
  int id=(int) arg;
53
  struct mess_type message;
54
  CAB ch=mchannelid[id];
55
 
56
  while(1) {
57
 
58
    message = (struct mess_type) cab_getmes(channel);
59
 
60
    switch (message.type) {
61
 
62
    case NEGOTIATE_CONTRACT:
63
      if (negotiate_contract(message.contract, message.server)!=FSF_ERR_CONTRACT_REJECTED)  {
64
 
65
 
66
      } else  {
67
      }
68
 
69
    break;
70
    case RENEGOTIATE_CONTRACT:
71
      renegotiate_contract(message.contract, message.server);
72
      break;                     
73
 
74
    default :
75
      break;
76
 
77
    }
78
 
79
 
80
 
81
    task_endcycle();
82
 
83
  }
84
}
85
 
86
int negotiate_contract
87
(const fsf_contract_parameters_t *contract,
88
 fsf_server_id_t                 *server)
89
{
90
  TIME T;
91
  TIME Q;
92
  /* Check if contract is initialized */
93
  if (!contract) return FSF_ERR_NOT_INITIALIZED;
94
 
95
  /* Admission Test */
96
  if (FSF_ADMISSION_TEST_IS_ENABLED)
97
    if (add_contract(contract))
98
      return FSF_ERR_CONTRACT_REJECTED;
99
 
100
 
101
 
102
}
103
 
104
 
105
int recalculate_contract(bandwidth_t U) {
106
  bandwidth_t current_bandwidth;
107
  unsigned int temp_U;
108
  int        Qt;
109
  int isok=0;
110
  int i=0;
111
 
112
  #ifdef FSF_DEBUG
113
    int temp;
114
 
115
    kern_printf("(Recalculate contract)");
116
  #endif
117
 
118
  /* The current bandwidth is the min bandwidth */
119
  //current_bandwidth=SERVER_return_bandwidth(fsf_server_level);
120
  #ifdef FSF_DEBUG
121
     kern_printf("(nserver %d)", current_server);
122
  #endif  
123
 
124
  do  {
125
    current_bandwidth=0;
126
    Qt=0;
127
    for (i=0; i<current_server; i++) {
128
      if (server_list[i].Qs!=0 && server_list[i].U<server_list[i].Umax)
129
         Qt+=server_list[i].Qs;
130
       current_bandwidth+=server_list[i].U;
131
    }
132
 
133
    #ifdef FSF_DEBUG
134
    kern_printf("(Total Quality %d)", Qt);
135
    #endif
136
    isok=1;
137
    for (i=0; i<current_server; i++) {
138
      if (server_list[i].Qs!=0 && server_list[i].U<server_list[i].Umax) {
139
        temp_U=server_list[i].U;
140
        server_list[i].U=U-current_bandwidth;
141
        mul32div32to32(server_list[i].U, server_list[i].Qs, Qt, server_list[i].U);
142
        temp_U+=server_list[i].U;
143
 
144
        if (temp_U<=server_list[i].Umin) {
145
           server_list[i].U=server_list[i].Umin;
146
        } else if (temp_U>server_list[i].Umax)  {
147
           server_list[i].U=server_list[i].Umax;
148
           isok=0;
149
        } else server_list[i].U=temp_U;
150
 
151
#ifdef FSF_DEBUG
152
        mul32div32to32(server_list[i].U,100, MAX_BANDWIDTH, temp);
153
        kern_printf("(Server %d bw %d)", server_list[i].server, temp);
154
#endif 
155
      }
156
    }  
157
 
158
  } while (!isok);
159
 
160
 return 0;
161
}