#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, ¶ms,
+ 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;
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;
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:
}
frescan_requests_free(req);
-
- return ret; // TODO: distinguish errors and failed negotiations
+ return 0;
}
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...
#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;
//
// 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;
//
}
/**
- * 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;
}
*
*/
-#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_
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;
}
/**
* =======================
* 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,
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);
}
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;
}
* @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
*
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;
/**
#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"
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);
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);
#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)
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
*
* @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
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];
extern int frescan_data_init(int fd, frescan_init_params_t *params);
-
-
#endif // _MARTE_FRESCAN_DATA_H_
* 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
#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
#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_
#define ERROR(s) {perror (s); exit (-1);}
#define NETWORK 0
-#define LOCAL_NODE 0
+#define LOCAL_NODE 1
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;
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);
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;
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);