Subversion Repositories shark

Rev

Rev 679 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*
 * Project: S.Ha.R.K.
 *
 * Coordinators:
 *   Giorgio Buttazzo    <giorgio@sssup.it>
 *   Paolo Gai           <pj@gandalf.sssup.it>
 *
 * Authors     :
 *   Trimarchi Michael   <trimarchi@gandalf.sssup.it>
 *   (see the web pages for full authors list)
 *
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
 *
 * http://www.sssup.it
 * http://retis.sssup.it
 * http://shark.sssup.it
 */


/*
 * Copyright (C) 2000 Giorgio Buttazzo, Paolo Gai
 *
 * This program 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 of the License, or
 * (at your option) any later version.
 *
 * This program 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
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *
 * CVS :        $Id: server-task.c,v 1.1 2004-05-20 12:13:55 trimarchi Exp $
 */


#include <kernel/kern.h>
#include <modules/cabs.h>
#include <string.h>
#include "message.h"



char    *mchannel[2]={"MCHANR","MCHANW"};
CAB     mchannelid[2];

TASK    service_task(void *arg) {
 
  int id=(int) arg;
  struct mess_type message;
  CAB ch=mchannelid[id];
 
  while(1) {
   
    message = (struct mess_type) cab_getmes(channel);
   
    switch (message.type) {
     
    case NEGOTIATE_CONTRACT:
      if (negotiate_contract(message.contract, message.server)!=FSF_ERR_CONTRACT_REJECTED)  {
       
     
      } else  {
      }
                         
    break;
    case RENEGOTIATE_CONTRACT:
      renegotiate_contract(message.contract, message.server);
      break;                     
                         
    default :
      break;

    }
   


    task_endcycle();
   
  }
}

int negotiate_contract
(const fsf_contract_parameters_t *contract,
 fsf_server_id_t                 *server)
{
  TIME T;
  TIME Q;
  /* Check if contract is initialized */
  if (!contract) return FSF_ERR_NOT_INITIALIZED;

  /* Admission Test */
  if (FSF_ADMISSION_TEST_IS_ENABLED)
    if (add_contract(contract))
      return FSF_ERR_CONTRACT_REJECTED;


 
}


int recalculate_contract(bandwidth_t U) {
  bandwidth_t current_bandwidth;
  unsigned int temp_U;
  int        Qt;
  int isok=0;
  int i=0;
 
  #ifdef FSF_DEBUG
    int temp;
 
    kern_printf("(Recalculate contract)");
  #endif

  /* The current bandwidth is the min bandwidth */
  //current_bandwidth=SERVER_return_bandwidth(fsf_server_level);
  #ifdef FSF_DEBUG
     kern_printf("(nserver %d)", current_server);
  #endif  
 
  do  {
    current_bandwidth=0;
    Qt=0;
    for (i=0; i<current_server; i++) {
      if (server_list[i].Qs!=0 && server_list[i].U<server_list[i].Umax)
         Qt+=server_list[i].Qs;
       current_bandwidth+=server_list[i].U;
    }

    #ifdef FSF_DEBUG
    kern_printf("(Total Quality %d)", Qt);
    #endif
    isok=1;
    for (i=0; i<current_server; i++) {
      if (server_list[i].Qs!=0 && server_list[i].U<server_list[i].Umax) {
        temp_U=server_list[i].U;
        server_list[i].U=U-current_bandwidth;
        mul32div32to32(server_list[i].U, server_list[i].Qs, Qt, server_list[i].U);
        temp_U+=server_list[i].U;
       
        if (temp_U<=server_list[i].Umin) {
           server_list[i].U=server_list[i].Umin;
        } else if (temp_U>server_list[i].Umax)  {
           server_list[i].U=server_list[i].Umax;
           isok=0;
        } else server_list[i].U=temp_U;
       
#ifdef FSF_DEBUG
        mul32div32to32(server_list[i].U,100, MAX_BANDWIDTH, temp);
        kern_printf("(Server %d bw %d)", server_list[i].server, temp);
#endif
      }
    }  

  } while (!isok);
 
 return 0;
}