]> rtime.felk.cvut.cz Git - frescor/fna.git/commitdiff
add the infraestructure for storing the negotiated contracts and performing the analy...
authorsangorrin <sangorrin@35b4ef3e-fd22-0410-ab77-dab3279adceb>
Tue, 22 Apr 2008 09:27:04 +0000 (09:27 +0000)
committersangorrin <sangorrin@35b4ef3e-fd22-0410-ab77-dab3279adceb>
Tue, 22 Apr 2008 09:27:04 +0000 (09:27 +0000)
Spare capacity is not done yet. Now we have to implement negotiation and cancel of contracts.

git-svn-id: http://www.frescor.org/private/svn/frescor/fna/trunk@1135 35b4ef3e-fd22-0410-ab77-dab3279adceb

14 files changed:
src_frescan/frescan_bwres.c
src_frescan/frescan_bwres.h
src_frescan/frescan_bwres_analysis.c
src_frescan/frescan_bwres_analysis.h
src_frescan/frescan_bwres_fna.c
src_frescan/frescan_bwres_messages.c
src_frescan/frescan_bwres_requests.h
src_frescan/frescan_bwres_threads.c
src_frescan/frescan_config.h
src_frescan/frescan_data.h
src_frescan/frescan_debug.h
tests/tests_frescan/test_frescan_bwres_init.c
tests/tests_frescan/test_frescan_bwres_negotiate_in_master.c
tests/tests_frescan/test_frescan_bwres_negotiate_in_slave.c

index 875138f1324bd0ddeeb8a166d3c811b4b36e97f0..33918f2032073877c972651ba097752283e96def 100644 (file)
@@ -18,6 +18,7 @@
 #include "frescan_bwres_requests.h"
 #include "frescan_bwres_messages.h"
 #include "frescan_bwres_threads.h"
+#include "frescan_bwres_analysis.h"
 #include "frescan_data.h"
 #include "frescan_debug.h"
 #include "frescan_config.h"
 int frescan_bwres_init(frescan_network_t net)
 {
         int ret;
-        frescan_server_params_t params;
+        frescan_server_params_t  server_params;  // TODO: improve this...
+        frescan_sa_init_params_t sa_init_params; // TODO: improve this...
 
-        // TODO: server params must be configurable
-        // TODO: initialization tree like in DTM
-        params.values.budget = 5;
-        params.values.period.tv_sec = 1;
-        params.values.period.tv_nsec = 0;
-        params.prio = FRESCAN_BWRES_NEG_MESSAGES_PRIO;
+        sa_init_params.max_prio = 30;
+        sa_init_params.min_prio = 1;
 
-        ret = frescan_servers_create(net, &params,
+        ret = frescan_sa_init(&the_networks[net].scenario,
+                              &sa_init_params);
+        if (ret != 0) return ret;
+
+        server_params.values.budget = 5;
+        server_params.values.period.tv_sec = 1;
+        server_params.values.period.tv_nsec = 0;
+        server_params.prio = FRESCAN_BWRES_NEG_MESSAGES_PRIO;
+
+        ret = frescan_servers_create(net, &server_params,
                                      &the_networks[net].neg_messages_ss_id);
         if (ret != 0) return ret;
 
+        // TODO: we have to add this negotiation contracts to the sa table
+
         ret = frescan_bwres_robjs_init(FRESCAN_REPLY_OBJECTS_MX_CEILING);
         if (ret != 0) return ret;
 
@@ -77,7 +86,8 @@ int frescan_bwres_init(frescan_network_t net)
 
 int frescan_bwres_negotiate(frescan_network_t net,
                             const frescan_contract_t *contract,
-                            frescan_ss_t *id)
+                            frescan_ss_t *id,
+                            bool *accepted)
 {
         int ret;
         frescan_request_id_t   req;
@@ -125,22 +135,18 @@ int frescan_bwres_negotiate(frescan_network_t net,
         switch (req_data->return_value) {
                 case FRESCAN_REQ_ACCEPTED:
                         DEBUG(FRESCAN_BWRES_ENABLE_DEBUG, "negotiation OK\n");
+                        *accepted = true;
                         *id = req_data->ss;
-                        ret = 0;
+                        server_params.prio = req_data->final_values.server_prio;
+                        ret = frescan_servers_update(net, &server_params, *id);
+                        if (ret != 0) return ret;
                         break;
 
                 case FRESCAN_REQ_NOT_ACCEPTED:
                         DEBUG(FRESCAN_BWRES_ENABLE_DEBUG, "negotiation FAIL\n");
+                        *accepted = false;
                         ret = frescan_servers_destroy(net, req_data->ss);
                         if (ret != 0) return ret;
-                        ret = -1;
-                        break;
-
-                case FRESCAN_REQ_ERROR:
-                        DEBUG(FRESCAN_BWRES_ENABLE_DEBUG, "negotiation ERROR\n");
-                        ret = frescan_servers_destroy(net, req_data->ss);
-                        if (ret != 0) return ret;
-                        ret = -1;
                         break;
 
                 default:
@@ -149,6 +155,5 @@ int frescan_bwres_negotiate(frescan_network_t net,
         }
 
         frescan_requests_free(req);
-
-        return ret; // TODO: distinguish errors and failed negotiations
+        return 0;
 }
index 830ac764ee3d688dc9395d9b202c1a7549f666a8..af476d67f0b88374314243efd665c6ba01ce590d 100644 (file)
@@ -24,7 +24,8 @@ extern int frescan_bwres_init(frescan_network_t net);
 
 extern int frescan_bwres_negotiate(frescan_network_t net,
                                    const frescan_contract_t *contract,
-                                   frescan_ss_t *id);
+                                   frescan_ss_t *id,
+                                   bool *accepted);
 
 // TODO: add other functions: renegotiate, cancel...
 
index eda9c8c1ee94ca1ad977afa2a62c8a04cb2620f3..cda54eef1fc311dafffd8175a23c2bff784bc4e7 100644 (file)
 #include "frescan_bwres_analysis.h"
 #undef ERROR
 #include "frescan_debug.h"
-// #include "frsh_sa_tools.h"
-
 
 /**
  * frescan_sa_init() - init the scenario
+ *
+ * @scenario: the scenario (in out)
+ * @params: init params (in)
  */
 
-int frescan_sa_init(frsh_sa_scenario_t *scenario,         // in out
-                    const frsh_sa_init_params_t *params)  // in
+int frescan_sa_init(frescan_sa_scenario_t *scenario,
+                    const frescan_sa_init_params_t *params)
 {
 //         int ret;
 //
 //         ret = frsh_sa_scenario_init(scenario, params);
 //         return ret;
-        WARNING("not implemented, returning 0\n");
+
+        INIT_LIST_HEAD(&scenario->contracts_head.list);
+        scenario->init_params = *params;
         return 0;
 }
 
 /**
  * frescan_sa_add_contract() - add a contract to the scenario
+ *
+ * @scenario: the scenario (in out)
+ * @contract: the new contract (in)
+ * @ss: the preallocated ss identificator (in)
+ * @node: the node this contract belongs to (in)
  */
 
-int frescan_sa_add_contract(frsh_sa_scenario_t    *scenario, // in out
-                            const frsh_contract_t *contract, // in
-                            frsh_vres_index_t     id)        // in
+int frescan_sa_add_contract(frescan_sa_scenario_t    *scenario,
+                            const frescan_contract_t *contract,
+                            frescan_ss_t             ss,
+                            frescan_node_t           node)
 {
 //         int ret;
 //
 //         ret = frsh_sa_scenario_add_vres(scenario, contract, id);
 //         return ret;
-        WARNING("not implemented, returning 0\n");
+        frescan_sa_contract_t *sa_contract;
+
+        sa_contract = &scenario->contracts[node][ss];
+
+        sa_contract->contract = *contract;
+        sa_contract->node     = node;
+        sa_contract->ss       = ss;
+
+        list_add_tail(&sa_contract->list,
+                      &scenario->contracts_head.list);
+
         return 0;
 }
 
 /**
  * frescan_sa_update_contract() - update a contract in the scenario
+ *
+ * @scenario: the scenario (in out)
+ * @ss: the ss identificator (in)
+ * @contract: the values to update the contract (in)
+ * @node: the node this contract belongs to (in)
  */
 
-int frescan_sa_update_contract(frsh_sa_scenario_t    *scenario, // in out
-                               frsh_vres_index_t     id,        // in
-                               const frsh_contract_t *contract) // in
+int frescan_sa_update_contract(frescan_sa_scenario_t   *scenario,
+                               frescan_ss_t             ss,
+                               const frescan_contract_t *contract,
+                               frescan_node_t           node)
 {
 //         int ret;
 //
 //         ret = frsh_sa_scenario_modify_vres(scenario, id, *contract);
 //         return ret;
-        WARNING("not implemented, returning 0\n");
+        frescan_sa_contract_t *sa_contract;
+
+        sa_contract = &scenario->contracts[node][ss];
+
+        sa_contract->contract = *contract;
+        sa_contract->node     = node;
+        sa_contract->ss       = ss;
+
         return 0;
 }
 
 /**
  * frescan_sa_remove_contract() - remove a contract from the scenario
+ *
+ * @scenario: the scenario (in out)
+ * @ss: the ss to remove (in)
+ * @node: the node this contract belongs to (in)
  */
 
-int frescan_sa_remove_contract(frsh_sa_scenario_t *scenario,  // in out
-                               frsh_vres_index_t id)          // in
+int frescan_sa_remove_contract(frescan_sa_scenario_t *scenario,
+                               frescan_ss_t          ss,
+                               frescan_node_t        node)
 {
 //         int ret;
 //
 //         ret = frsh_sa_scenario_del_vres(scenario, id);
 //         return ret;
-        WARNING("not implemented, returning 0\n");
+        frescan_sa_contract_t *sa_contract;
+
+        sa_contract = &scenario->contracts[node][ss];
+        list_del(&sa_contract->list);
+
         return 0;
 }
 
 /**
  * frescan_sa_sched_test() - perform a scheduling test on the scenario
+ *
+ * @scenario: the scenario (in out)
+ * @success: if the scenario is schedulable or not (out)
  */
 
-int frescan_sa_sched_test(frsh_sa_scenario_t *scenario,  // in out
-                          bool *success)                 // out
+int frescan_sa_sched_test(frescan_sa_scenario_t *scenario,
+                          bool *success)
 {
 //         int ret;
 //
@@ -169,15 +213,35 @@ int frescan_sa_sched_test(frsh_sa_scenario_t *scenario,  // in out
 // error:
 //         *success = false;
 //         return ret;
-        WARNING("not implemented, returning 0\n");
+
+        struct list_head *pos;
+        frescan_sa_contract_t *sa_contract;
+
+        list_for_each(pos, &scenario->contracts_head.list) {
+                sa_contract = list_entry(pos, frescan_sa_contract_t, list);
+                sa_contract->final_values.server_prio = sa_contract->contract.prio;
+                DEBUG(FRESCAN_SA_ENABLE_DEBUG,
+                      "sa_contract, node:%d ss:%d, c:%d t:(%d,%d) p:%d\n",
+                      sa_contract->node, sa_contract->ss,
+                      sa_contract->contract.min_values.budget,
+                      sa_contract->contract.min_values.period.tv_sec,
+                      sa_contract->contract.min_values.period.tv_nsec,
+                      sa_contract->contract.prio);
+        }
+
+        WARNING("test not implemented, returning 0 and success by default\n");
+        *success = true;
+
         return 0;
 }
 
 /**
  * frescan_sa_spare_capacity() - distribute the remaining spare capacity
+ *
+ * @scenario: the scenario (in out)
  */
 
-int frescan_sa_spare_capacity(frsh_sa_scenario_t *scenario) // in out
+int frescan_sa_spare_capacity(frescan_sa_scenario_t *scenario)
 {
 //         int ret;
 //
@@ -189,18 +253,27 @@ int frescan_sa_spare_capacity(frsh_sa_scenario_t *scenario) // in out
 }
 
 /**
- * sa_get_final_values() - get the final values
+ * frescan_sa_get_final_values() - get the final values
+ *
+ * @scenario: the scenario (in)
+ * @ss: the ss from which we want the final values (in)
+ * @node: the node this contract belongs to (in)
+ * @final_values: the final values (out)
  */
 
-int sa_get_final_values(const frsh_sa_scenario_t *scenario,      // in
-                        frsh_vres_index_t id,                    // in
-                        frescan_sa_final_values_t *final_values) // out
+
+int frescan_sa_get_final_values(const frescan_sa_scenario_t *scenario,
+                                frescan_ss_t              ss,
+                                frescan_node_t            node,
+                                frescan_sa_final_values_t *final_values)
 {
 //         final_values->budget   = scenario->sa_vres_alloc[id].c;
 //         final_values->period   = scenario->sa_vres_alloc[id].t;
 //         final_values->deadline = scenario->sa_vres_alloc[id].d;
 //         final_values->priority = scenario->sa_vres_alloc[id].p;
 //         return 0;
-        WARNING("not implemented, returning 0\n");
+
+        *final_values = scenario->contracts[node][ss].final_values;
+
         return 0;
 }
index c2e2e5b1c1fd44ace663d4e793fa60a601a36644..ad9fca6aa4a71a559fe4ef80250e7731d7bb764a 100644 (file)
  *
  */
 
-#ifndef _FRESCAN_SCHED_ANALYSIS_H_
-#define _FRESCAN_SCHED_ANALYSIS_H_
+#ifndef _FRESCAN_BWRES_ANALYSIS_H_
+#define _FRESCAN_BWRES_ANALYSIS_H_
 
-#include "frsh.h"
-
-// #include "frsh_sa_scenario.h"
-typedef int frsh_sa_scenario_t;
-typedef int frsh_sa_init_params_t;
-typedef int frsh_vres_index_t;
-typedef int frescan_sa_final_values_t;
+#include "frescan.h"
+#include "frescan_data.h"
 
 /**
  * frescan_sa_init() - init the scenario
+ *
+ * @scenario: the scenario (in out)
+ * @params: init params (in)
  */
 
-extern int frescan_sa_init(frsh_sa_scenario_t *scenario,         // in out
-                           const frsh_sa_init_params_t *params); // in
+extern int frescan_sa_init(frescan_sa_scenario_t *scenario,
+                           const frescan_sa_init_params_t *params);
 
 /**
  * frescan_sa_add_contract() - add a contract to the scenario
+ *
+ * @scenario: the scenario (in out)
+ * @contract: the new contract (in)
+ * @ss: the preallocated ss identificator (in)
+ * @node: the node this contract belongs to (in)
  */
 
-extern int frescan_sa_add_contract(frsh_sa_scenario_t    *scenario, // in out
-                                   const frsh_contract_t *contract, // in
-                                   frsh_vres_index_t     id);       // in
+extern int frescan_sa_add_contract(frescan_sa_scenario_t    *scenario,
+                                   const frescan_contract_t *contract,
+                                   frescan_ss_t             ss,
+                                   frescan_node_t           node);
 
 /**
  * frescan_sa_update_contract() - update a contract in the scenario
+ *
+ * @scenario: the scenario (in out)
+ * @ss: the ss identificator (in)
+ * @contract: the values to update the contract (in)
+ * @node: the node this contract belongs to (in)
  */
 
-extern int frescan_sa_update_contract(frsh_sa_scenario_t    *scenario, // in out
-                                      frsh_vres_index_t     id,        // in
-                                      const frsh_contract_t *contract);// in
+extern int frescan_sa_update_contract(frescan_sa_scenario_t *scenario,
+                                      frescan_ss_t          ss,
+                                      const frescan_contract_t *contract,
+                                      frescan_node_t           node);
 
 /**
  * frescan_sa_remove_contract() - remove a contract from the scenario
+ *
+ * @scenario: the scenario (in out)
+ * @ss: the ss to remove (in)
+ * @node: the node this contract belongs to (in)
  */
 
-extern int frescan_sa_remove_contract(frsh_sa_scenario_t *scenario,  // in out
-                                      frsh_vres_index_t id);         // in
+extern int frescan_sa_remove_contract(frescan_sa_scenario_t *scenario,
+                                      frescan_ss_t          ss,
+                                      frescan_node_t        node);
 
 /**
  * frescan_sa_sched_test() - perform a scheduling test on the scenario
+ *
+ * @scenario: the scenario (in out)
+ * @success: if the scenario is schedulable or not (out)
  */
 
-extern int frescan_sa_sched_test(frsh_sa_scenario_t *scenario,  // in out
-                                 bool *success);                // out
+extern int frescan_sa_sched_test(frescan_sa_scenario_t *scenario,
+                                 bool *success);
 
 /**
  * frescan_sa_spare_capacity() - distribute the remaining spare capacity
+ *
+ * @scenario: the scenario (in out)
  */
 
-extern int frescan_sa_spare_capacity(frsh_sa_scenario_t *scenario); // in out
+extern int frescan_sa_spare_capacity(frescan_sa_scenario_t *scenario);
 
 /**
- * sa_get_final_values() - get the final values
+ * frescan_sa_get_final_values() - get the final values
+ *
+ * @scenario: the scenario (in)
+ * @ss: the ss from which we want the final values (in)
+ * @node: the node this contract belongs to (in)
+ * @final_values: the final values (out)
  */
 
-extern int sa_get_final_values(const frsh_sa_scenario_t *scenario,       // in
-                               frsh_vres_index_t id,                     // in
-                               frescan_sa_final_values_t *final_values); // out
+extern int frescan_sa_get_final_values(const frescan_sa_scenario_t *scenario,
+                                       frescan_ss_t              ss,
+                                       frescan_node_t            node,
+                                       frescan_sa_final_values_t *final_values);
 
-#endif // _FRESCAN_REQUESTS_QUEUE_H_
+#endif // _FRESCAN_BWRES_ANALYSIS_H_
index 10babf2bc21f031d55f58ed7f37478a0e8c2fdd2..2262ac68332a06e9c83a9bedf88dc0cc96266b56 100644 (file)
@@ -111,35 +111,39 @@ int frescan_fna_contract_negotiate
                  const frsh_contract_t *contract,
                  fna_vres_id_t *vres)
 {
-        int accepted;
+        int ret;
+        bool accepted;
         frescan_ss_t ss;
         frescan_contract_t frescan_contract;
 
         DEBUG(FRESCAN_FNA_ENABLE_DEBUG,
               "frsh contract->frescan contract\n");
 
-        // TODO: budget is stored as number of can frames in tv_sec
+        // NOTE: budget is stored as number of can frames in tv_sec
         frescan_contract.min_values.budget = contract->budget_min.tv_sec;
         frescan_contract.min_values.period = contract->period_max;
 
         frescan_contract.max_values.budget = contract->budget_max.tv_sec;
         frescan_contract.max_values.period = contract->period_min;
 
+        // TODO: put 0 if we want the sa module to assign the prios
         frescan_contract.prio = contract->preemption_level;
 
         DEBUG(FRESCAN_FNA_ENABLE_DEBUG, "calling frescan_bwres_negotiate\n");
-        accepted = frescan_bwres_negotiate((frescan_network_t)resource_id,
-                                           &frescan_contract,
-                                           &ss); // TODO: associate the contract with the ss
+        ret = frescan_bwres_negotiate((frescan_network_t)resource_id,
+                                       &frescan_contract,
+                                       &ss,
+                                       &accepted);
+        if (ret != 0) return -1;
 
-        if (accepted == 0) {
+        if (accepted == true) {
                 DEBUG(FRESCAN_FNA_ENABLE_DEBUG, "contract accepted\n");
                 *vres = (fna_vres_id_t)ss;
+                return 0;
         } else {
                 DEBUG(FRESCAN_FNA_ENABLE_DEBUG, "contract not accepted\n");
+                return -1; // TODO: change to constant FNA_REJECTED
         }
-
-        return accepted;
 }
 
 /**
index df69e1f5267d17cebb0e391a56c18b8ac6421794..6d1982aef87f8545120ff2e68b749bfd622dc680 100644 (file)
@@ -208,20 +208,21 @@ static int frescan_cancel_message_to_request(const uint8_t *msg,
  *  =======================
  *  This message is sent from the MASTER to a slave as a reply to a
  *  FRESCAN_REQ_NEG or a FRESCAN_REQ_RENEG, to say if they were admited.
- *  It contains the type 'REPNEG', the request ID of the slave and a
- *  return value to say if the contract is admited, not admited or if
- *  there was an error.
+ *  It contains the type 'REPNEG', the request ID of the slave, a
+ *  return value to say if the contract is admited or not, and the final
+ *  values if it was admited
  *
- *  +-------------------------------+
- *  | 'REPNEG' | REQ | RETURN_VALUE |
- *  +-------------------------------+
+ *  +----------------------------------------------+
+ *  | 'REPNEG' | REQ | RETURN_VALUE | FINAL_VALUES |
+ *  +----------------------------------------------+
  *
  */
 
 struct frescan_rep_neg_message_t {
-        frescan_request_type_t   type;
-        frescan_request_id_t     req;
-        frescan_request_retval_t return_value;
+        frescan_request_type_t    type;
+        frescan_request_id_t      req;
+        frescan_request_retval_t  return_value;
+        frescan_sa_final_values_t final_values;
 }  __attribute__ ((packed));
 
 static int frescan_request_to_repneg_message(const frescan_request_data_t *data,
@@ -234,6 +235,7 @@ static int frescan_request_to_repneg_message(const frescan_request_data_t *data,
         repneg_msg->type         = FRESCAN_REP_NEG;
         repneg_msg->req          = data->req;
         repneg_msg->return_value = data->return_value;
+        repneg_msg->final_values = data->final_values;
 
         return sizeof(struct frescan_rep_neg_message_t);
 }
@@ -248,6 +250,7 @@ static int frescan_repneg_message_to_request(const uint8_t *msg,
         data->type         = FRESCAN_REP_NEG;
         data->req          = repneg_msg->req;
         data->return_value = repneg_msg->return_value;
+        data->final_values = repneg_msg->final_values;
 
         return 0;
 }
index b25e2031345b31ad00f833e3fd4ae513aec14b25..5bc448525a4d3e8a0424dffc8ac3daab92a4e3c6 100644 (file)
@@ -32,7 +32,8 @@
  * @ss: the local sporadic server ID
  * @request_node: the node that performed the request
  * @req: the request id of the SLAVE to identify the request in the reply
- * @return_value: the value returned in a Reply
+ * @return_value: the value returned in a Reply (accepted or not)
+ * @final_values: the values for the ss after the negotiation
  * @net: the network instance where this request belongs to
  * @robj: a reply object to wait until a negotiation is completed
  *
@@ -50,18 +51,18 @@ typedef enum {
 typedef enum {
         FRESCAN_REQ_ACCEPTED      =  0,  // the (re)negotiation is accepted
         FRESCAN_REQ_NOT_ACCEPTED  =  1,  // the (re)negotiation is not accepted
-        FRESCAN_REQ_ERROR         =  2,  // error during the (re)negotiation
 } frescan_request_retval_t;
 
 typedef struct {
-        frescan_request_type_t   type;
-        frescan_contract_t       *contract;
-        frescan_ss_t             ss;
-        frescan_node_t           request_node;
-        frescan_request_id_t     req;
-        frescan_request_retval_t return_value;
-        frescan_network_t        net;
-        frescan_robj_id_t        robj;
+        frescan_request_type_t    type;
+        frescan_contract_t        *contract;
+        frescan_ss_t              ss;
+        frescan_node_t            request_node;
+        frescan_request_id_t      req;
+        frescan_request_retval_t  return_value;
+        frescan_sa_final_values_t final_values;
+        frescan_network_t         net;
+        frescan_robj_id_t         robj;
 } frescan_request_data_t;
 
 /**
index 86eda2e28ad147ca817a20306dba30447fde2305..3216a1b2779c40fbbeb0cd2d79e5342537bff1fe 100644 (file)
@@ -19,6 +19,7 @@
 #include "frescan_bwres_threads.h"
 #include "frescan_bwres_messages.h"
 #include "frescan_bwres_requests.h"
+#include "frescan_bwres_analysis.h"
 #include "frescan_config.h"
 #include "frescan_debug.h"
 #include "frescan_data.h"
@@ -175,19 +176,37 @@ static void frescan_manager_neg(frescan_request_data_t *req_data)
         DEBUG(FRESCAN_MANAGER_ENABLE_DEBUG, "negotiation request\n");
 
         if (the_networks[req_data->net].local_node == FRESCAN_NEG_MASTER_NODE) {
+                // scheduling analysis
+                ret = frescan_sa_add_contract
+                                (&the_networks[req_data->net].scenario,
+                                 req_data->contract,
+                                 req_data->ss,
+                                 req_data->request_node);
+                assert(ret == 0);
 
-                // NOTE: req_data->ss is an INPUT parameter
-                accepted = true; // TODO: sched analysis
-                ret = 0;  // TODO: sched analysis
+                ret = frescan_sa_sched_test
+                                (&the_networks[req_data->net].scenario,
+                                 &accepted);
+                assert(ret == 0);
 
                 if (accepted) {
+                        ret = frescan_sa_get_final_values
+                                        (&the_networks[req_data->net].scenario,
+                                         req_data->ss,
+                                         req_data->request_node,
+                                         &req_data->final_values);
+                        assert(ret == 0);
                         req_data->return_value = FRESCAN_REQ_ACCEPTED;
                 } else {
-                        req_data->return_value = (ret == 0) ?
-                                                  FRESCAN_REQ_NOT_ACCEPTED :
-                                                  FRESCAN_REQ_ERROR;
+                        ret = frescan_sa_remove_contract
+                                        (&the_networks[req_data->net].scenario,
+                                         req_data->ss,
+                                         req_data->request_node);
+                        assert(ret == 0);
+                        req_data->return_value = FRESCAN_REQ_NOT_ACCEPTED;
                 }
 
+                // signal or reply the results
                 if (req_data->request_node == FRESCAN_NEG_MASTER_NODE) {
                         DEBUG(FRESCAN_MANAGER_ENABLE_DEBUG, "master local\n");
                         ret = frescan_bwres_robjs_signal(req_data->robj);
@@ -241,6 +260,7 @@ static void frescan_manager_repneg(frescan_request_data_t *req_data)
         assert(ret == 0);
 
         neg_req_data->return_value = req_data->return_value;
+        neg_req_data->final_values = req_data->final_values;
 
         ret = frescan_bwres_robjs_signal(neg_req_data->robj);
         assert(ret == 0);
index d19f1b3524d9547f1766e7ed6313faa45882e4e7..0bb0c9bf68add2880375021643f16ecdc85da882 100644 (file)
@@ -45,6 +45,8 @@
 #define FRESCAN_ACCEPTOR_THREAD_PRIO FRESCAN_NEG_THREAD_PRIO + 1
 #define FRESCAN_BWRES_NEG_MESSAGES_PRIO 8
 #define FRESCAN_NEG_CHANNEL       0
+#define FRESCAN_MX_NODES          2
+#define FRESCAN_MX_CONTRACTS      (FRESCAN_MX_NODES*FRESCAN_MX_IDS)
 
 #define FRESCAN_MLOCK_T            unsigned
 #define FRESCAN_CREATE_LOCK(l)
index 2c7070c195f144e4c826b067a28ad29d326cafe1..71354326cca555412a665f2fa3ecd84bb1b9942d 100644 (file)
@@ -116,6 +116,33 @@ typedef struct {
         frescan_prio_t prio;
 } frescan_contract_t;
 
+/**
+ * frescan_sa_xxx scheduling analysis types
+ */
+
+typedef struct {
+        frescan_prio_t server_prio;
+} frescan_sa_final_values_t;
+
+typedef struct {
+        frescan_contract_t        contract;
+        frescan_node_t            node;
+        frescan_ss_t              ss;
+        frescan_sa_final_values_t final_values;
+        struct list_head          list;
+} frescan_sa_contract_t;
+
+typedef struct {
+        frescan_prio_t    max_prio;
+        frescan_prio_t    min_prio;
+} frescan_sa_init_params_t;
+
+typedef struct {
+        frescan_sa_contract_t contracts[FRESCAN_MX_NODES][FRESCAN_MX_IDS];
+        frescan_sa_contract_t contracts_head;
+        frescan_sa_init_params_t init_params;
+} frescan_sa_scenario_t;
+
 /**
  * frescan_prio_queue_t - priority queue
  *
@@ -177,6 +204,7 @@ typedef struct {
  * @id_fp_queues: the same as id_queues but for fp messages, which have
  *                id=FRESCAN_MX_IDS and are distinguised through their
  *                priorities.
+ * @scenario: the scheduling analysis scenario for the network
  *
  * the implementation can handle several FRESCAN networks at the same time
  * in the same node, so we need a place to store its internal data. The data
@@ -197,6 +225,7 @@ typedef struct {
         frescan_prio_t last_packet_prio;
         frescan_packet_t *id_queues[FRESCAN_MX_IDS];      // TODO: alloc at init
         frescan_packet_t *id_fp_queues[FRESCAN_MX_PRIOS]; // TODO: alloc at init
+        frescan_sa_scenario_t scenario;
 } frescan_network_data_t;
 
 extern frescan_network_data_t the_networks[FRESCAN_MX_NETWORKS];
@@ -208,6 +237,4 @@ extern frescan_network_data_t the_networks[FRESCAN_MX_NETWORKS];
 
 extern int frescan_data_init(int fd, frescan_init_params_t *params);
 
-
-
 #endif // _MARTE_FRESCAN_DATA_H_
index 18909e24b29da485560a5ed574eefb3aea5823af..2cdaaa6c5b770ddd2dc727f9852d5913061d09c9 100644 (file)
@@ -40,7 +40,7 @@
  * DEBUGGING FLAGS to enable/disable debugging messages
  **/
 
-#define FRESCAN_SERVERS_ENABLE_DEBUG    true
+#define FRESCAN_SERVERS_ENABLE_DEBUG    false
 #define FRESCAN_PACKETPOOL_ENABLE_DEBUG false
 #define FRESCAN_FRAG_ENABLE_DEBUG       false
 #define FRESCAN_INIT_ENABLE_DEBUG       false
@@ -50,7 +50,7 @@
 #define FRESCAN_SENT_HOOK_ENABLE_DEBUG  false
 #define FRESCAN_QUEUES_ENABLE_DEBUG     false
 #define FRESCAN_HW_BUFFER_ENABLE_DEBUG  false
-#define FRESCAN_REPLENSH_ENABLE_DEBUG   true
+#define FRESCAN_REPLENSH_ENABLE_DEBUG   false
 #define FRESCAN_ROBJS_ENABLE_DEBUG      false
 #define FRESCAN_BWRES_ENABLE_DEBUG      false
 #define FRESCAN_REQUESTS_ENABLE_DEBUG   false
@@ -58,5 +58,6 @@
 #define FRESCAN_ACCEPTOR_ENABLE_DEBUG   false
 #define FRESCAN_FNA_ENABLE_DEBUG        false
 #define FRESCAN_MESSAGES_ENABLE_DEBUG   false
+#define FRESCAN_SA_ENABLE_DEBUG         false
 
 #endif // _MARTE_FRESCAN_DEBUG_H_
index 1de4734503c791e7ecba5ffaf15b2b6459c0368d..19b1127b5e82e05f10b3d3b724b7b3f7b757510f 100644 (file)
@@ -8,7 +8,7 @@
 #define ERROR(s) {perror (s); exit (-1);}
 
 #define NETWORK 0
-#define LOCAL_NODE 0
+#define LOCAL_NODE 1
 
 int main ()
 {
index 224d78d0c38772508d3d24bb48a351a4e12cd1df..9bea770e98f9d623652abc28d2383fc26350c784 100644 (file)
@@ -16,6 +16,8 @@ int main ()
         frescan_init_params_t init_params;
         frescan_ss_t ss;
         frescan_contract_t contract;
+        bool accepted;
+        frescan_server_params_t server_params;
 
         init_params.net = NETWORK;
         init_params.node = LOCAL_NODE;
@@ -31,8 +33,27 @@ int main ()
         ret = frescan_bwres_init(NETWORK);
         if (ret != 0) ERROR ("could not init BWRES");
 
-        ret = frescan_bwres_negotiate(NETWORK, &contract, &ss);
-        if (ret != 0) ERROR ("could not negotiate succesfully");
+        contract.min_values.budget = 5;
+        contract.min_values.period.tv_sec  = 3;
+        contract.min_values.period.tv_nsec = 69;
+        contract.prio = 7;
+
+        ret = frescan_bwres_negotiate(NETWORK, &contract, &ss, &accepted);
+        if (ret != 0) ERROR ("could not negotiate");
+
+        if (accepted) {
+                printf("The contract was accepted, ss:%u\n", ss);
+                ret = frescan_servers_get_data(NETWORK, &server_params, ss);
+                if (ret != 0) ERROR ("could not get servers data");
+
+                printf("B:%u, T=(%u,%u), P:%u\n",
+                       server_params.values.budget,
+                       server_params.values.period.tv_sec,
+                       server_params.values.period.tv_nsec,
+                       server_params.prio);
+        } else {
+                printf("The contract was not accepted\n");
+        }
 
         while (1) {
                 sleep(1);
index b81d4b7ab26324682596cdf9e82863725377bd8b..3a0191541459d2f4cd4d3dc98c5d032beabec141 100644 (file)
@@ -18,6 +18,7 @@ int main ()
         frescan_ss_t ss;
         frescan_contract_t contract;
         frescan_server_params_t server_params;
+        bool accepted;
 
         init_params.net = NETWORK;
         init_params.node = LOCAL_NODE;
@@ -42,18 +43,22 @@ int main ()
         contract.prio = 5;
 
         printf("Negotiating a contract\n");
-        ret = frescan_bwres_negotiate(NETWORK, &contract, &ss);
+        ret = frescan_bwres_negotiate(NETWORK, &contract, &ss, &accepted);
         if (ret != 0) ERROR ("could not negotiate succesfully");
 
-        printf("negotiation was succesful, ss:%u\n", ss);
-        ret = frescan_servers_get_data(NETWORK, &server_params, ss);
-        if (ret != 0) ERROR ("could not get servers data");
+        if (accepted) {
+                printf("The contract was accepted, ss:%u\n", ss);
+                ret = frescan_servers_get_data(NETWORK, &server_params, ss);
+                if (ret != 0) ERROR ("could not get servers data");
 
-        printf("B:%u, T=(%u,%u), P:%u\n",
-               server_params.values.budget,
-               server_params.values.period.tv_sec,
-               server_params.values.period.tv_nsec,
-               server_params.prio);
+                printf("B:%u, T=(%u,%u), P:%u\n",
+                       server_params.values.budget,
+                       server_params.values.period.tv_sec,
+                       server_params.values.period.tv_nsec,
+                       server_params.prio);
+        } else {
+                printf("The contract was not accepted\n");
+        }
 
         while (1) {
                 sleep(1);