**/
int rtep_fna_init(const frsh_resource_id_t resource_id)
{
- int err = 0;
+ int err = 0;
- DEBUG("calling rtep_adainit\n");
+ DEBUG("calling rtep_adainit\n");
- // init Ada bindings
- rtep_adainit();
+ // init Ada bindings
+ rtep_adainit();
- DEBUG("calling freelist_init\n");
+ DEBUG("calling freelist_init\n");
- // initialize the freelist to handle the rtep_vres
- err = frsh_freelist_init(&rtep_vres_freelist, MAX_N_RTEP_BWRES_VRES);
- if (err != 0) return -1;
+ // initialize the freelist to handle the rtep_vres
+ err = frsh_freelist_init(&rtep_vres_freelist, MAX_N_RTEP_BWRES_VRES);
+ if (err != 0) return -1;
- DEBUG("calling rtep_bwres_init\n");
+ DEBUG("calling rtep_bwres_init\n");
- return rtep_bwres_init();
+ return rtep_bwres_init();
}
///////////////////////////////////////////////////////////////////
*
**/
int rtep_fna_contract_negotiate
- (const frsh_resource_id_t resource_id,
- const frsh_contract_t *contract,
- fna_vres_id_t *vres)
+ (const frsh_resource_id_t resource_id,
+ const frsh_contract_t *contract,
+ fna_vres_id_t *vres)
{
- rtep_bwres_contract_t rtep_contract;
- int accepted;
- int pos;
-
- // convert FRSH contract to RTEP BWRES contract
- rtep_contract.period_max = contract->period_max;
- rtep_contract.deadline = contract->deadline;
- rtep_contract.prio = contract->preemption_level;
- // in RTEP BWRES, budget is given in number of packets. We do a little trick
- // in the function bytes_to_network_budget to use a the field tv_sec from
- // the timespec in frsh_contract to store the budget in bytes directly
- rtep_contract.budget_min = contract->budget_min.tv_sec;
-
- // allocate a free internal vres.
- pos = frsh_freelist_alloc(&rtep_vres_freelist);
-
- if (pos < 0) {
- DEBUG("not enough resources\n");
- return -1;
- }
-
- DEBUG("calling rtep_bwres_contract_negotiate\n");
- // negotiate the contract
- accepted = rtep_bwres_contract_negotiate
- (&rtep_contract, &rtep_vres_list[pos]);
-
- // if accepted assign the vres, if not deallocate the rtep_vres
- if (accepted == 0) {
- DEBUG("contract accepted\n");
- *vres = (fna_vres_id_t)pos;
- } else {
- DEBUG("contract not accepted\n");
- frsh_freelist_free(&rtep_vres_freelist, pos);
- }
-
- return accepted;
+ rtep_bwres_contract_t rtep_contract;
+ int accepted;
+ int pos;
+
+ // convert FRSH contract to RTEP BWRES contract
+ rtep_contract.period_max = contract->period_max;
+ rtep_contract.deadline = contract->deadline;
+ rtep_contract.prio = contract->preemption_level;
+ // in RTEP BWRES, budget is given in number of packets. We do a little trick
+ // in the function bytes_to_network_budget to use a the field tv_sec from
+ // the timespec in frsh_contract to store the budget in bytes directly
+ rtep_contract.budget_min = contract->budget_min.tv_sec;
+
+ // allocate a free internal vres.
+ pos = frsh_freelist_alloc(&rtep_vres_freelist);
+
+ if (pos < 0) {
+ DEBUG("not enough resources\n");
+ return -1;
+ }
+
+ DEBUG("calling rtep_bwres_contract_negotiate\n");
+ // negotiate the contract
+ accepted = rtep_bwres_contract_negotiate
+ (&rtep_contract, &rtep_vres_list[pos]);
+
+ // if accepted assign the vres, if not deallocate the rtep_vres
+ if (accepted == 0) {
+ DEBUG("contract accepted\n");
+ *vres = (fna_vres_id_t)pos;
+ } else {
+ DEBUG("contract not accepted\n");
+ frsh_freelist_free(&rtep_vres_freelist, pos);
+ }
+
+ return accepted;
}
/**
*
**/
int rtep_fna_contract_renegotiate_sync
- (const frsh_resource_id_t resource_id,
- const fna_vres_id_t vres,
- const frsh_contract_t *new_contract)
+ (const frsh_resource_id_t resource_id,
+ const fna_vres_id_t vres,
+ const frsh_contract_t *new_contract)
{
- rtep_bwres_contract_t rtep_contract;
- int accepted;
- int pos = (int) vres;
-
- // convert FRSH contract to RTEP BWRES contract
- rtep_contract.period_max = new_contract->period_max;
- rtep_contract.deadline = new_contract->deadline;
- rtep_contract.prio = new_contract->preemption_level;
- // in RTEP BWRES, budget is given in number of packets. We do a little trick
- // in the function bytes_to_network_budget to use a the field tv_sec from
- // the timespec in frsh_contract to store the budget in bytes directly
- rtep_contract.budget_min = new_contract->budget_min.tv_sec;
-
- // renegotiate the contract
- accepted = rtep_bwres_contract_renegotiate_sync
- (&rtep_vres_list[pos], &rtep_contract);
-
- return accepted;
+ rtep_bwres_contract_t rtep_contract;
+ int accepted;
+ int pos = (int) vres;
+
+ // convert FRSH contract to RTEP BWRES contract
+ rtep_contract.period_max = new_contract->period_max;
+ rtep_contract.deadline = new_contract->deadline;
+ rtep_contract.prio = new_contract->preemption_level;
+ // in RTEP BWRES, budget is given in number of packets. We do a little trick
+ // in the function bytes_to_network_budget to use a the field tv_sec from
+ // the timespec in frsh_contract to store the budget in bytes directly
+ rtep_contract.budget_min = new_contract->budget_min.tv_sec;
+
+ // renegotiate the contract
+ accepted = rtep_bwres_contract_renegotiate_sync
+ (&rtep_vres_list[pos], &rtep_contract);
+
+ return accepted;
}
/**
*
**/
int rtep_fna_contract_renegotiate_async
- (const frsh_resource_id_t resource_id,
- const fna_vres_id_t vres,
- const frsh_contract_t *new_contract,
- frsh_signal_t signal_to_notify,
- frsh_signal_info_t signal_info)
+ (const frsh_resource_id_t resource_id,
+ const fna_vres_id_t vres,
+ const frsh_contract_t *new_contract,
+ frsh_signal_t signal_to_notify,
+ frsh_signal_info_t signal_info)
{
- return 0;
+ return 0;
}
/**
*
**/
int rtep_fna_vres_get_renegotiation_status
- (const frsh_resource_id_t resource_id,
- const fna_vres_id_t vres,
- frsh_renegotiation_status_t *renegotiation_status)
+ (const frsh_resource_id_t resource_id,
+ const fna_vres_id_t vres,
+ frsh_renegotiation_status_t *renegotiation_status)
{
- return 0;
+ return 0;
}
/**
*
**/
int rtep_fna_vres_destroy
- (const frsh_resource_id_t resource_id,
- const fna_vres_id_t vres)
+ (const frsh_resource_id_t resource_id,
+ const fna_vres_id_t vres)
{
- int err = 0;
- int pos = (int) vres;
+ int err = 0;
+ int pos = (int) vres;
- // cancel de negotiated contract (the function spread results among nodes)
- err = rtep_bwres_vres_destroy (&rtep_vres_list[pos]);
- if (err != 0) return -1;
+ // cancel de negotiated contract (the function spread results
+ // among nodes)
+ err = rtep_bwres_vres_destroy (&rtep_vres_list[pos]);
+ if (err != 0) return -1;
- // free the element in the rtep_vres list
- err = frsh_freelist_free(&rtep_vres_freelist, pos);
- if (err != 0) return -1;
+ // free the element in the rtep_vres list
+ err = frsh_freelist_free(&rtep_vres_freelist, pos);
+ if (err != 0) return -1;
- return 0;
+ return 0;
}
/**
*
**/
int rtep_fna_vres_get_contract
- (const frsh_resource_id_t resource_id,
- const fna_vres_id_t vres,
- frsh_contract_t *contract)
+ (const frsh_resource_id_t resource_id,
+ const fna_vres_id_t vres,
+ frsh_contract_t *contract)
{
- return 0;
+ return 0;
}
/**
*
**/
int rtep_fna_vres_get_usage
- (const frsh_resource_id_t resource_id,
- const fna_vres_id_t vres,
- struct timespec *usage)
+ (const frsh_resource_id_t resource_id,
+ const fna_vres_id_t vres,
+ struct timespec *usage)
{
- return 0;
+ return 0;
}
/**
*
**/
int rtep_fna_vres_get_remaining_budget
- (const frsh_resource_id_t resource_id,
- const fna_vres_id_t vres,
- struct timespec *remaining_budget)
+ (const frsh_resource_id_t resource_id,
+ const fna_vres_id_t vres,
+ struct timespec *remaining_budget)
{
- return 0;
+ return 0;
}
/**
*
**/
int rtep_fna_vres_get_budget_and_period
- (const frsh_resource_id_t resource_id,
- const fna_vres_id_t vres,
- struct timespec *budget,
- struct timespec *period)
+ (const frsh_resource_id_t resource_id,
+ const fna_vres_id_t vres,
+ struct timespec *budget,
+ struct timespec *period)
{
- return 0;
+ return 0;
}
/*@}*/
*
**/
int rtep_fna_resource_get_capacity
- (const frsh_resource_id_t resource_id,
- const int importance,
- uint32_t *capacity)
+ (const frsh_resource_id_t resource_id,
+ const int importance,
+ uint32_t *capacity)
{
- return 0;
+ return 0;
}
/**
*
**/
int rtep_fna_resource_get_total_weight
- (const frsh_resource_id_t resource_id,
- const int importance,
- int *total_weight)
+ (const frsh_resource_id_t resource_id,
+ const int importance,
+ int *total_weight)
{
- return 0;
+ return 0;
}
/**
*
**/
int rtep_fna_vres_decrease_capacity
- (const frsh_resource_id_t resource_id,
- const fna_vres_id_t vres,
- const struct timespec new_budget,
- const struct timespec new_period)
+ (const frsh_resource_id_t resource_id,
+ const fna_vres_id_t vres,
+ const struct timespec new_budget,
+ const struct timespec new_period)
{
- return 0;
+ return 0;
}
///////////////////////////////////////////////////////////////////
*
**/
int rtep_fna_send_sync
- (const fna_endpoint_data_t *endpoint,
- const void *msg,
- const size_t size)
+ (const fna_endpoint_data_t *endpoint,
+ const void *msg,
+ const size_t size)
{
- return 0;
+ DEBUG("dest: %d, chan: %d, size: %d, server: %d\n",
+ endpoint->destination, endpoint->stream_id, size,
+ rtep_vres_list[endpoint->vres].server_id);
+
+ // TODO: check errors
+ rtep_server_send_info
+ ((rtep_station_id_t) endpoint->destination,
+ (rtep_channel_t) endpoint->stream_id,
+ (uint8_t *) msg,
+ size,
+ rtep_vres_list[endpoint->vres].server_id,
+ 1); // blocking
+ return 0;
}
/**
*
**/
int rtep_fna_send_async
- (const fna_endpoint_data_t *endpoint,
- const void *msg,
- const size_t size)
+ (const fna_endpoint_data_t *endpoint,
+ const void *msg,
+ const size_t size)
{
- DEBUG("dest: %d, chan: %d, size: %d, server: %d\n",
- endpoint->destination, endpoint->stream_id, size,
- rtep_vres_list[endpoint->vres].server_id);
-
- // TODO: check errors
- rtep_server_send_info
- ((rtep_station_id_t) endpoint->destination,
- (rtep_channel_t) endpoint->stream_id,
- (uint8_t *) msg,
- size,
- rtep_vres_list[endpoint->vres].server_id,
- 0); // not blocking
- return 0;
+ DEBUG("dest: %d, chan: %d, size: %d, server: %d\n",
+ endpoint->destination, endpoint->stream_id, size,
+ rtep_vres_list[endpoint->vres].server_id);
+
+ // TODO: check errors
+ rtep_server_send_info
+ ((rtep_station_id_t) endpoint->destination,
+ (rtep_channel_t) endpoint->stream_id,
+ (uint8_t *) msg,
+ size,
+ rtep_vres_list[endpoint->vres].server_id,
+ 0); // not blocking
+ return 0;
}
/**
*
**/
int rtep_fna_receive_sync
- (const fna_endpoint_data_t *endpoint,
- void *buffer,
- const size_t buffer_size,
- size_t *received_bytes,
- frsh_network_address_t *from)
+ (const fna_endpoint_data_t *endpoint,
+ void *buffer,
+ const size_t buffer_size,
+ size_t *received_bytes,
+ frsh_network_address_t *from)
{
- rtep_priority_t prio;
- rtep_station_id_t rtep_from;
- rtep_channel_t chan = (rtep_channel_t) endpoint->stream_id;
+ rtep_priority_t prio;
+ rtep_station_id_t rtep_from;
+ rtep_channel_t chan = (rtep_channel_t) endpoint->stream_id;
- // TODO: checks for errors
- rtep_recv_info
- (&rtep_from,
- chan,
- (uint8_t *) buffer,
- buffer_size,
- received_bytes,
- &prio);
+ // TODO: checks for errors
+ rtep_recv_info
+ (&rtep_from,
+ chan,
+ (uint8_t *) buffer,
+ buffer_size,
+ received_bytes,
+ &prio);
- *from = rtep_from;
+ *from = rtep_from;
- DEBUG(" %u bytes, from %u, prio %u\n", *received_bytes, rtep_from, prio);
+ DEBUG(" %u bytes, from %u, prio %u\n",
+ *received_bytes, rtep_from, prio);
- return 0;
+ return 0;
}
/**
*
**/
int rtep_fna_receive_async
- (const fna_endpoint_data_t *endpoint,
- void *buffer,
- const size_t buffer_size,
- size_t *received_bytes,
- frsh_network_address_t *from)
+ (const fna_endpoint_data_t *endpoint,
+ void *buffer,
+ const size_t buffer_size,
+ size_t *received_bytes,
+ frsh_network_address_t *from)
{
- return 0;
+ return 0;
}
/**
*
**/
int rtep_fna_send_endpoint_get_status
- (const fna_endpoint_data_t *endpoint,
- int *number_of_pending_messages,
- frsh_endpoint_network_status_t *network_status,
- frsh_protocol_status_t *protocol_status)
+ (const fna_endpoint_data_t *endpoint,
+ int *number_of_pending_messages,
+ frsh_endpoint_network_status_t *network_status,
+ frsh_protocol_status_t *protocol_status)
{
- return 0;
+ return 0;
}
/**
* FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
**/
int rtep_fna_receive_endpoint_created
- (fna_endpoint_data_t *endpoint)
+ (fna_endpoint_data_t *endpoint)
{
- return 0;
+ return 0;
}
/**
*
**/
int rtep_fna_receive_endpoint_get_status
- (const fna_endpoint_data_t *endpoint,
- int *number_of_pending_messages,
- frsh_endpoint_network_status_t *network_status,
- frsh_protocol_status_t *protocol_status)
+ (const fna_endpoint_data_t *endpoint,
+ int *number_of_pending_messages,
+ frsh_endpoint_network_status_t *network_status,
+ frsh_protocol_status_t *protocol_status)
{
- return 0;
+ return 0;
}
//////////////////////////////////////////////////////////////////////
*
**/
int rtep_fna_network_get_max_message_size
- (const frsh_resource_id_t resource_id,
- const frsh_network_address_t destination,
- size_t *max_size)
+ (const frsh_resource_id_t resource_id,
+ const frsh_network_address_t destination,
+ size_t *max_size)
{
- int is_multicast;
-
- if (max_size == NULL) {
- return -1;
- }
-
- is_multicast = rtep_valid_multicast_id ((rtep_station_id_t) destination);
- if (is_multicast) {
- *max_size = MULTICAST_MTU;
- } else {
- *max_size = MAX_RTEP_MTU;
- }
- return 0;
+ int is_multicast;
+
+ if (max_size == NULL) {
+ return -1;
+ }
+
+ is_multicast = rtep_valid_multicast_id((rtep_station_id_t) destination);
+ if (is_multicast) {
+ *max_size = MULTICAST_MTU;
+ } else {
+ *max_size = MAX_RTEP_MTU;
+ }
+ return 0;
}
/**
*
**/
int rtep_fna_network_bytes_to_budget
- (const frsh_resource_id_t resource_id,
- const size_t nbytes,
- struct timespec *budget)
+ (const frsh_resource_id_t resource_id,
+ const size_t nbytes,
+ struct timespec *budget)
{
- int number_of_packets;
+ int number_of_packets;
- if (budget == NULL || nbytes < 0) {
- return -1;
- }
+ if (budget == NULL || nbytes < 0) {
+ return -1;
+ }
// we measure the budget in number of RTEP packets of maximum size
- number_of_packets = nbytes / MAX_RTEP_MTU + 1;
+ number_of_packets = nbytes / MAX_RTEP_MTU + 1;
// we store the budget in number of packets instead of in time. We
// use a field in the timespec structure.
- budget->tv_sec = number_of_packets;
- DEBUG("bytes: %d -> budget: %d\n", nbytes, budget->tv_sec);
- return 0;
+ budget->tv_sec = number_of_packets;
+ DEBUG("bytes: %d -> budget: %d\n", nbytes, budget->tv_sec);
+ return 0;
}
/**
*
**/
int rtep_fna_network_budget_to_bytes
- (const frsh_resource_id_t resource_id,
- const struct timespec *budget,
- size_t *nbytes)
+ (const frsh_resource_id_t resource_id,
+ const struct timespec *budget,
+ size_t *nbytes)
{
- int number_of_packets;
-
- if (budget == NULL || nbytes == NULL) {
- return -1;
- }
- number_of_packets = budget->tv_sec;
- *nbytes = number_of_packets * MAX_RTEP_MTU;
- return 0;
+ int number_of_packets;
+
+ if (budget == NULL || nbytes == NULL) {
+ return -1;
+ }
+ number_of_packets = budget->tv_sec;
+ *nbytes = number_of_packets * MAX_RTEP_MTU;
+ return 0;
}
/**
*
**/
int rtep_fna_network_get_min_eff_budget
- (const frsh_resource_id_t resource_id,
- struct timespec *budget)
+ (const frsh_resource_id_t resource_id,
+ struct timespec *budget)
{
- if (budget == NULL) {
- return -1;
- }
- budget->tv_sec = 1;
- return 0;
+ if (budget == NULL) {
+ return -1;
+ }
+ budget->tv_sec = 1;
+ return 0;
}
// GLOBAL variable to install the network protocol in FRESCOR
fna_operations_t rtep_fna_operations = {
- .fna_init = rtep_fna_init,
- .fna_contract_negotiate = rtep_fna_contract_negotiate,
- .fna_contract_renegotiate_sync = rtep_fna_contract_renegotiate_sync,
- .fna_contract_renegotiate_async = rtep_fna_contract_renegotiate_async,
- .fna_vres_get_renegotiation_status = rtep_fna_vres_get_renegotiation_status,
- .fna_vres_destroy = rtep_fna_vres_destroy,
- .fna_vres_get_contract = rtep_fna_vres_get_contract,
- .fna_vres_get_usage = rtep_fna_vres_get_usage,
- .fna_vres_get_remaining_budget = rtep_fna_vres_get_remaining_budget,
- .fna_vres_get_budget_and_period = rtep_fna_vres_get_budget_and_period,
- .fna_resource_get_capacity = rtep_fna_resource_get_capacity,
- .fna_resource_get_total_weight = rtep_fna_resource_get_total_weight,
- .fna_vres_decrease_capacity = rtep_fna_vres_decrease_capacity,
- .fna_send_sync = rtep_fna_send_sync,
- .fna_send_async = rtep_fna_send_async,
- .fna_receive_sync = rtep_fna_receive_sync,
- .fna_receive_async = rtep_fna_receive_async,
- .fna_send_endpoint_get_status = rtep_fna_send_endpoint_get_status,
- .fna_receive_endpoint_created = rtep_fna_receive_endpoint_created,
- .fna_receive_endpoint_get_status = rtep_fna_receive_endpoint_get_status,
- .fna_network_get_max_message_size = rtep_fna_network_get_max_message_size,
- .fna_network_bytes_to_budget = rtep_fna_network_bytes_to_budget,
- .fna_network_budget_to_bytes = rtep_fna_network_budget_to_bytes,
- .fna_network_get_min_eff_budget = rtep_fna_network_get_min_eff_budget
+ .fna_init = rtep_fna_init,
+ .fna_contract_negotiate = rtep_fna_contract_negotiate,
+ .fna_contract_renegotiate_sync = rtep_fna_contract_renegotiate_sync,
+ .fna_contract_renegotiate_async = rtep_fna_contract_renegotiate_async,
+ .fna_vres_get_renegotiation_status = rtep_fna_vres_get_renegotiation_status,
+ .fna_vres_destroy = rtep_fna_vres_destroy,
+ .fna_vres_get_contract = rtep_fna_vres_get_contract,
+ .fna_vres_get_usage = rtep_fna_vres_get_usage,
+ .fna_vres_get_remaining_budget = rtep_fna_vres_get_remaining_budget,
+ .fna_vres_get_budget_and_period = rtep_fna_vres_get_budget_and_period,
+ .fna_resource_get_capacity = rtep_fna_resource_get_capacity,
+ .fna_resource_get_total_weight = rtep_fna_resource_get_total_weight,
+ .fna_vres_decrease_capacity = rtep_fna_vres_decrease_capacity,
+ .fna_send_sync = rtep_fna_send_sync,
+ .fna_send_async = rtep_fna_send_async,
+ .fna_receive_sync = rtep_fna_receive_sync,
+ .fna_receive_async = rtep_fna_receive_async,
+ .fna_send_endpoint_get_status = rtep_fna_send_endpoint_get_status,
+ .fna_receive_endpoint_created = rtep_fna_receive_endpoint_created,
+ .fna_receive_endpoint_get_status = rtep_fna_receive_endpoint_get_status,
+ .fna_network_get_max_message_size = rtep_fna_network_get_max_message_size,
+ .fna_network_bytes_to_budget = rtep_fna_network_bytes_to_budget,
+ .fna_network_budget_to_bytes = rtep_fna_network_budget_to_bytes,
+ .fna_network_get_min_eff_budget = rtep_fna_network_get_min_eff_budget
};