]> rtime.felk.cvut.cz Git - frescor/fwp.git/blobdiff - fwp/mngr/fwp_admctrl.c
Whitespace fixes
[frescor/fwp.git] / fwp / mngr / fwp_admctrl.c
index d42ea1b0ebbec34e9220806d22c511e22204c258..e42809afd233424e4a1d23688c471a4ac301fb4a 100644 (file)
 #include <fwp.h>
 #include "fwp_idl.h"
 #include "fwp_admctrl.h"
+#include <ul_log.h>
+#include <ul_logreg.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 };
@@ -149,12 +151,11 @@ int fwp_admctrl_utilization(struct fres_sa_scenario *scenario, void *priv,
 {
        int utilization = 0;
 
-       const int rate = 1*1000*1000;
-       const bool erp_ofdm = false;
-       const bool short_preamble = false;
-       struct fres_sa_contract *c, *c_new = NULL;
+       const int rate = 54*1000*1000;
+       const bool erp_ofdm = true;
+       const bool short_preamble = true;
+       struct fres_sa_contract *c;
        long int period_usec;
-       fres_block_basic *basic;
        fres_block_fwp_sched *fwp_sched;
 
        size_t bytes; 
@@ -162,22 +163,24 @@ int fwp_admctrl_utilization(struct fres_sa_scenario *scenario, void *priv,
        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 */
-               frsh_network_budget_to_bytes(FRSH_NETPF_FWP,&basic->budget,&bytes);
                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 +
@@ -195,49 +198,53 @@ int fwp_admctrl_utilization(struct fres_sa_scenario *scenario, void *priv,
                tmp_usec = frame_duration(ACK_FRAME_SIZE, rate, erp_ofdm, 
                                        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 */
+               //duration_usec *= 2; /* For demo, we have always STA-to-STA */
 
-               basic = fres_contract_get_basic(c->contract);
-               period_usec = fosa_rel_time_to_msec(basic->period)*1000;
                if (c->contract == c->new) {
-                       c_new = c;
                        if (period_usec == 0) {
+                               ul_logmsg("Period is zero!\n");
                                goto not_schedulable;
                        }
+
+                       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 {
+                               d = 100/*sec*/*1000*1000;
+                       }
+                       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;
+                       fres_contract_add_block(c->contract, FRES_BLOCK_FWP_SCHED, fwp_sched);
                }
+
                utilization += (long long)(duration_usec * 10000) / period_usec;
        }
        
-       if (!c_new) {
-               *schedulable = false;
-               return -1;      
-       }       
        if (utilization >= 10000 * 96/100) {
                goto not_schedulable;
-       } 
-       
-       basic = fres_contract_get_basic(c_new->contract);
-       /*int d = c->deadline_usec;*/
-       long int d = fosa_rel_time_to_msec(basic->period)*1000;         
-       if (d <= 0) d = 100*1000*1000;
-       if (d < 50000) {
-               goto not_schedulable;
-       };
-       
+       }
+       scenario->utilization = utilization/100; /* For GUI */
+
+       ul_logmsg("accepted\n");
        *schedulable = true;
-       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;
-       fres_contract_add_block(c_new->contract, FRES_BLOCK_FWP_SCHED, fwp_sched);      
        return 0;
 
 not_schedulable:
+       ul_logmsg("rejected\n");
        *schedulable = false;
        return 0;
 }