flow_control.c
Go to the documentation of this file.
00001 /*------------------------------------------------------------------------
00002  *---------------------           RT-WMP              --------------------
00003  *------------------------------------------------------------------------
00004  *                                                         V7.0B  11/05/10
00005  *
00006  *
00007  *  File: ./src/core/flow_control.c
00008  *  Authors: Danilo Tardioli
00009  *  ----------------------------------------------------------------------
00010  *  Copyright (C) 2000-2010, Universidad de Zaragoza, SPAIN
00011  *
00012  *  Contact Addresses: Danilo Tardioli                   dantard@unizar.es
00013  *
00014  *  RT-WMP is free software; you can  redistribute it and/or  modify it
00015  *  under the terms of the GNU General Public License  as published by the
00016  *  Free Software Foundation;  either  version 2, or (at  your option) any
00017  *  later version.
00018  *
00019  *  RT-WMP  is distributed  in the  hope  that  it will be   useful, but
00020  *  WITHOUT  ANY  WARRANTY;     without  even the   implied   warranty  of
00021  *  MERCHANTABILITY  or  FITNESS FOR A  PARTICULAR PURPOSE.    See the GNU
00022  *  General Public License for more details.
00023  *
00024  *  You should have received  a  copy of  the  GNU General Public  License
00025  *  distributed with RT-WMP;  see file COPYING.   If not,  write to the
00026  *  Free Software  Foundation,  59 Temple Place  -  Suite 330,  Boston, MA
00027  *  02111-1307, USA.
00028  *
00029  *  As a  special exception, if you  link this  unit  with other  files to
00030  *  produce an   executable,   this unit  does  not  by  itself cause  the
00031  *  resulting executable to be covered by the  GNU General Public License.
00032  *  This exception does  not however invalidate  any other reasons why the
00033  *  executable file might be covered by the GNU Public License.
00034  *
00035  *----------------------------------------------------------------------*/
00036 
00037 #include "config/compiler.h"
00038 #include "include/flow_control.h"
00039 #include "include/queues.h"
00040 
00041 static int * count;
00042 static int * status;
00043 static int n_nodes;
00044 
00045 void initFlowControl(int numNodes){
00046         int i = 0;
00047         n_nodes = numNodes;
00048         count= (int *) MALLOC(numNodes*sizeof(int));
00049         status=(int *) MALLOC(numNodes*sizeof(int));
00050         for (i = 0; i < numNodes; i++){
00051                 status[i]=FC_CONTINUE_SEND;
00052                 count [i]=0;
00053         }
00054 }
00055 
00056 void freeFlowControl(void){
00057    FREE(count);
00058    FREE(status);
00059 }
00060 
00061 void fc_sent(int i){
00062         count[i] = 0;
00063 }
00064 
00065 int fc_get_status(int i){
00066         return status[i];
00067 }
00068 
00069 void fc_new_pap(){
00070         int i;
00071         for (i = 0 ; i< n_nodes ;i++){
00072                 count[i]++;
00073         }
00074 }
00075 
00076 int fc_can_send(int i){
00077         return (count[i] > status[i]);
00078 }
00079 
00080 void fc_set_status(int i, int j){
00081         if (status[i] >= FC_CRITICAL){
00082                 if(j == FC_DISCARDED){
00083                         status[i]= status[i] * 4;
00084                 }else if (j == FC_QUARTER){
00085                         status[i]= status[i] * 100 / 75;
00086                 } else if (j == FC_HALF){
00087                         status[i]= status[i] * 100 / 50;
00088                 } else if (j == FC_CONTINUE_SEND) {
00089                         status[i]= status[i] * 100 / 25;
00090                 }
00091         }else {
00092                 status[i]=j;
00093         }
00094 }
00095 
00096 int fc_get_congestion(){
00097         int ret, free_pos_rx_queue = (wmp_queue_rx_get_size() - wmp_queue_rx_get_len());
00098 #ifdef NODE_BASED
00099         if (free_pos_rx_queue > status.N_NODES){
00100                 ret = FC_CONTINUE_SEND;
00101         } else if (free_pos_rx_queue > (status.N_NODES / 2)) {
00102                 ret = FC_HALF;
00103         } else if (free_pos_rx_queue > 0){
00104                 wmp_queue_rx_push_received(&m);
00105                 ret = FC_QUARTER;
00106         } else{
00107                 ret = FC_DISCARDED;
00108         }
00109 #else
00110         int qs = wmp_queue_rx_get_size();
00111         if (free_pos_rx_queue >  qs / 2 ){
00112                 ret = FC_CONTINUE_SEND;
00113         } else if (free_pos_rx_queue > (qs / 4)) {
00114                 ret = FC_HALF;
00115         } else if (free_pos_rx_queue > qs / 8){
00116                 ret = FC_QUARTER;
00117         } else if (free_pos_rx_queue > qs / 16){
00118                 ret = FC_CRITICAL;
00119         } else if (free_pos_rx_queue > 0) {
00120                 ret = FC_WARNING;
00121         } else {
00122                 ret = FC_DISCARDED;
00123         }
00124         return ret;
00125 #endif
00126 }
00127 
00128 
00129 
00130 


ros_rt_wmp
Author(s): Danilo Tardioli, dantard@unizar.es
autogenerated on Fri Jan 3 2014 12:07:54