]> rtime.felk.cvut.cz Git - frescor/fwp.git/blobdiff - fwp/mngr/fwp_admctrl.c
fwp_mgr: Log utilization when accepting/rejecting contracts
[frescor/fwp.git] / fwp / mngr / fwp_admctrl.c
index 01229dde25ce440a719142b0024988787e4ca6d9..1d257d433e657cf2634ecbbfe96ca4a0c3604b55 100644 (file)
@@ -1,4 +1,59 @@
+/**************************************************************************/
+/* ---------------------------------------------------------------------- */
+/* 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 FWP (Frescor WLAN Protocol)                     */
+/*                                                                       */
+/* FWP is free software; you can redistribute it and/or modify it        */
+/* under terms of the GNU General Public License as published by the     */
+/* Free Software Foundation; either version 2, or (at your option) any   */
+/* later version.  FWP 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 FWP; see file       */
+/* COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,  */
+/* Cambridge, MA 02139, USA.                                             */
+/*                                                                       */
+/* As a special exception, including FWP header files in a file,         */
+/* instantiating FWP generics or templates, or linking other files       */
+/* with FWP 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 <fres_sa_scenario.h>
+#include <fwp.h>
+#include "fwp_idl.h"
+#include "fwp_admctrl.h"
+#include <ul_log.h>
+#include <ul_logreg.h>
+#include "fwp_utils.h"
+
+UL_LOG_CUST(ulogd_fwp_admctrl);
+ul_log_domain_t ulogd_fwp_admctrl = {UL_LOGL_MSG, "fwp_admctrl"};
+UL_LOGREG_SINGLE_DOMAIN_INIT_FUNCTION(fwp_admctrl_logreg_domains, ulogd_fwp_admctrl);
 
 /* TODO: Find out the real value and determine what influences it (MTU
  *      of the interface minus header sizes?).  */
 #define CTS_FRAME_SIZE 14
 #define ACK_FRAME_SIZE 14
 
-#define BITRATE_BPS (1000*1000)
 #define ASLOTTIME_USEC 20      /* 802.11g-2003 p. 46 */
 #define ASIFSTIME_USEC 10
 #define ADIFSTIME_USEC (ASIFSTIME_USEC + 2*ASLOTTIME_USEC)
 #define AAIFSTIME_USEC(n) (ASIFSTIME_USEC + (n)*ASLOTTIME_USEC)
 
-#define TXTIME_USEC(bytes) ((int64_t)(bytes) * 8 * SEC_TO_USEC / BITRATE_BPS)
-
-
 /* Default values from 802.11e */
 const int aifsn[FWP_AC_NUM] = { 2, 2, 3, 7 };
 const int cwmin[FWP_AC_NUM] = { 3, 7, 15, 15 };
@@ -47,7 +98,7 @@ int fwp_reserved_utilization;
  */
 static int frame_duration(uint16_t length, int rate_bps, bool erp_ofdm, bool short_preamble)
 {
-       uint32_t duration_usec;
+       uint32_t duration_usec = 0;
 
        if (!erp_ofdm) {
                duration_usec = ((int64_t)(length) * 8 * SEC_TO_USEC / rate_bps);
@@ -100,86 +151,100 @@ int fwp_admctrl_utilization(struct fres_sa_scenario *scenario, void *priv,
                                 bool *schedulable)
 {
        int utilization = 0;
-
-       const int rate = 1*1000*1000;
-       const bool erp_ofdm = false;
-       const bool short_preamble = false;
-
-       int bytes, duration_usec, tmp_usec, fragments;
-       int ac = FWP_AC_VO; /* FIXME: assign to AC before this
-                            * loop based on deadlines */
+       struct frm_fwp_priv *pr = priv;
+       const int rate = pr->rate_mbps*1000*1000;
+       struct fres_sa_contract *c;
+       long int period_usec;
+       fres_block_fwp_sched *fwp_sched;
+
+       size_t bytes; 
+       long int duration_usec, tmp_usec;
+       int fragments;
+       int ac = FWP_AC_VO; 
        
-       fres_sa_scenario_for_each_contract(scenario, c) {
+       fres_sa_scenario_for_each_no_cancel_contract(scenario, c) {
                fres_block_basic *basic;
                char id[40];
                fres_contract_id_to_string(id, &c->contract->id, sizeof(id));
                basic = fres_contract_get_basic(c->contract);
 
-               printf("  processing: id=%s, period=%ld ms, budget=%ld ms\n",
+               frsh_network_budget_to_bytes(FRSH_NETPF_FWP,&basic->budget,&bytes);
+               ul_logmsg("processing: id=%s, period=%ld ms, budget=%lu bytes\n",
                       id,
                       fosa_rel_time_to_msec(basic->period),
-                      fosa_rel_time_to_msec(basic->budget));
+                      (long unsigned int)bytes);
+
+               period_usec = basic ? fosa_rel_time_to_msec(basic->period)*1000 : 0;
 
                /* Calculate protocol overhead */
-               bytes = fwp_fna_network_budget_to_bytes(basic->budget);
                fragments = (bytes + MTU - 1) / MTU;
 
-               if (fragments == 0)
+               if (fragments == 0 && period_usec != 0)
                        continue;
 
                const int data_overhead = UDP_HEADER_SIZE + IP_HEADER_SIZE +
                        LLC_HEADER_SIZE + MAC_FCS_SIZE;
 
                duration_usec = frame_duration(data_overhead + bytes%MTU, rate, 
-                                               erp_ofdm, short_preamble);
-               tmp_usec = frame_duration(data_overhead + MTU, rate, erp_ofdm, 
-                                               short_preamble);
+                                              pr->erp_ofdm, pr->short_preamble);
+               tmp_usec = frame_duration(data_overhead + MTU, rate,
+                                         pr->erp_ofdm, pr->short_preamble);
                duration_usec += tmp_usec*(fragments-1);
                /* Add average backoff - assume there is no collision */
                tmp_usec = ASLOTTIME_USEC*fragments*pisvejc[ac];
                duration_usec += (aifsn[ac] + cwmin[ac]/2)*tmp_usec;
                /* We use ACK and ignore burst */
-               tmp_usec = frame_duration(ACK_FRAME_SIZE, rate, erp_ofdm, 
-                                       short_preamble) + ASIFSTIME_USEC; 
+               tmp_usec = frame_duration(ACK_FRAME_SIZE, rate,
+                                         pr->erp_ofdm, pr->short_preamble)
+                       + ASIFSTIME_USEC; 
                duration_usec += fragments * tmp_usec; 
+               //printf("duration: %ld ms\n", duration_usec/1000);
 
                /* TODO: If STA-to-STA, multiply it by two. Note that
                 * AP may use different values for backoff. */
                duration_usec *= 2; /* For demo, we have always STA-to-STA */
-               if (contract->period_usec == 0) {
-                       if (contdata == contdata_new) {
-                               contdata->status = FWP_CONT_NOTNEGOTIATED;
-                               return;
+
+               if (c->contract == c->new) {
+                       if (period_usec == 0) {
+                               ul_logmsg("Period is zero!\n");
+                               goto not_schedulable;
                        }
-               }
-               utilization += (long long)(duration_usec * 10000) / contract->period_usec;
-       }
 
-       if (contdata_new) {
-               if (utilization >= 10000 * 96/100) {
-                       contdata_new->status = FWP_CONT_NOTNEGOTIATED;
-               } else {
-                       struct fwp_contract *c = &contdata_new->contract;
-                       int d = c->deadline_usec;
-                       if (d <= 0) d = 100*1000*1000;
-                       if (d < 50000) {
-                               contdata_new->status = FWP_CONT_NOTNEGOTIATED;
+                       frsh_rel_time_t deadline;
+                       long int d;
+                       if (fres_contract_get_deadline(&c->contract, &deadline)) {
+                               d = fosa_rel_time_to_msec(deadline)*1000;
                        } else {
-                               contdata_new->status = FWP_CONT_RESERVED;
+                               d = 100/*sec*/*1000*1000;
                        }
-
-                       contdata_new->vres_params.ac_id =
+                       if (d < 30/*msec*/*1000) {
+                               ul_logmsg("Deadline shorter than 30 ms!\n");
+                               goto not_schedulable;
+                       };
+                       
+                       fwp_sched = malloc(sizeof(*fwp_sched));
+                       fwp_sched->ac_id =
                                d <  100*1000 ? FWP_AC_VO :
                                d <  500*1000 ? FWP_AC_VI :
                                d < 1000*1000 ? FWP_AC_BE :
                                FWP_AC_BK;
-                       contdata_new->vres_params.budget = c->budget;
-                       contdata_new->vres_params.period_usec = c->period_usec; 
+                       fres_contract_add_block(c->contract, FRES_BLOCK_FWP_SCHED, fwp_sched);
                }
-       }
 
-       /* Update utilization for GUI */
-       if (contdata_new == NULL || contdata_new->status == FWP_CONT_RESERVED) {
-               fwp_reserved_utilization = utilization;
+               utilization += (long long)(duration_usec * 10000) / period_usec;
        }
+       
+       if (utilization >= 10000 * 96/100 && !pr->bypass) {
+               goto not_schedulable;
+       }
+       scenario->utilization = utilization/100; /* For GUI */
+
+       ul_logmsg("accepted (utilization=%d%%)\n", utilization/100);
+       *schedulable = true;
+       return 0;
+
+not_schedulable:
+       ul_logmsg("rejected (utilization=%d%%)\n", utilization/100);
+       *schedulable = false;
+       return 0;
 }