EXPORT_PATH = $(HOME)/export
# enable networks with their flag (change DISABLED<->ENABLED)
-RTEP_ENABLE = RTEP_FNA_ENABLED
-UNIX_ENABLE = UNIX_FNA_DISABLED
+RTEP_ENABLE = RTEP_FNA_DISABLED
+UNIX_ENABLE = UNIX_FNA_ENABLED
# the gcc to use
CC = mgcc
#include <stdbool.h> /* for bool */
#include "fna_configuration.h"
-#ifdef RTEP
+#ifdef RTEP_FNA_ENABLED
#include "rtep.h"
#endif
* FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
*
**/
-#ifdef RTEP
-int frsh_rtep_map_network_address
- (const frsh_resource_id_t resource_id,
- const rtep_station_id_t in_address,
- frsh_network_address_t *out_address);
+#ifdef RTEP_FNA_ENABLED
+int frsh_rtep_map_network_address(const frsh_resource_id_t resource_id,
+ const rtep_station_id_t in_address,
+ frsh_network_address_t *out_address);
#endif
/**
* FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
*
**/
-#ifdef RTEP
-int frsh_rtep_map_stream_id
- (const frsh_resource_id_t resource_id,
- const rtep_channel_t in_stream,
- frsh_stream_id_t *out_stream);
+#ifdef RTEP_FNA_ENABLED
+int frsh_rtep_map_stream_id(const frsh_resource_id_t resource_id,
+ const rtep_channel_t in_stream,
+ frsh_stream_id_t *out_stream);
#endif
/*@}*/
* FNA_ERR_REJECTED_CONTRACT : if the renegotiation fails \n
*
**/
-#ifdef RTEP
+#ifdef RTEP_FNA_ENABLED
int frsh_rtep_negotiation_messages_vres_renegotiate
(const frsh_resource_id_t resource_id,
const struct timespec *period);
* FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
*
**/
-#ifdef RTEP
+#ifdef RTEP_FNA_ENABLED
int frsh_rtep_negotiation_messages_vres_get_period
(const frsh_resource_id_t resource_id,
struct timespec *period);
* FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
*
**/
-#ifdef RTEP
+#ifdef RTEP_FNA_ENABLED
int frsh_rtep_service_thread_vres_renegotiate
(const frsh_resource_id_t resource_id,
const struct timespec *budget,
* FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
*
**/
-#ifdef RTEP
+#ifdef RTEP_FNA_ENABLED
int frsh_rtep_service_thread_vres_get_budget_and_period
(const frsh_resource_id_t resource_id,
struct timespec *budget,
-.PHONY: none clean
+.PHONY: none clean libfna.a
none:
@exec echo -e "\nPlease introduce a target, i.e: 'make test_dtm_xxx.exe'";
@exec echo -e "\n>> Building $@: ";
@if [ -f $< ]; \
then \
- $(CC) $(CFLAGS) $< $(LDFLAGS) &> /dev/null; \
+ $(CC) $(CFLAGS) $< $(LDFLAGS); \
fi; # -o $@ (fix marte mgcc)
@exec echo ">> End Building $@";
fna_operations_t *fna_operations[FNA_MAX_NETWORKS] = {
- &rtep_fna_operations,
- // &unix_fna_operations,
+ // &rtep_fna_operations,
+ &unix_fna_operations,
// NULL, // resource_id 0
NULL, // resource_id 1
NULL, // resource_id 2
#include <malloc.h> /* for malloc and free */
#include "unix_fna.h" /* function prototypes */
-#if 0
+#if 1
#include <stdio.h>
#define DEBUG(x,args...) printf("%s: " x, __func__ , ##args)
#else
// INITIALIZATION
//////////////////////////////////////////////////////////////////////
+char *the_unix_stream_ids[MX_UNIX_STREAM_IDS] = {
+ "/tmp/stream00",
+ "/tmp/stream01",
+ "/tmp/stream02",
+ "/tmp/stream03",
+ "/tmp/stream04",
+ "/tmp/stream05"
+};
+
/**
* unix_fna_init()
*
int unix_fna_init(const frsh_resource_id_t resource_id)
{
- DEBUG("starting unix fna\n");
- return 0;
+ DEBUG("NOT IMPLEMENTED\n");
+ return 0;
}
///////////////////////////////////////////////////////////////////
const frsh_contract_t *contract,
fna_vres_id_t *vres)
{
- return 0;
+ DEBUG("NOT IMPLEMENTED\n");
+ return 0;
}
/**
const fna_vres_id_t vres,
const frsh_contract_t *new_contract)
{
- return 0;
+ DEBUG("NOT IMPLEMENTED\n");
+ return 0;
}
/**
frsh_signal_t signal_to_notify,
frsh_signal_info_t signal_info)
{
- return 0;
+ DEBUG("NOT IMPLEMENTED\n");
+ return 0;
}
/**
const fna_vres_id_t vres,
frsh_renegotiation_status_t *renegotiation_status)
{
- return 0;
+ DEBUG("NOT IMPLEMENTED\n");
+ return 0;
}
/**
int unix_fna_vres_destroy(const frsh_resource_id_t resource_id,
const fna_vres_id_t vres)
{
- return 0;
+ DEBUG("NOT IMPLEMENTED\n");
+ return 0;
}
/**
const fna_vres_id_t vres,
frsh_contract_t *contract)
{
- return 0;
+ DEBUG("NOT IMPLEMENTED\n");
+ return 0;
}
/**
const fna_vres_id_t vres,
struct timespec *usage)
{
- return 0;
+ DEBUG("NOT IMPLEMENTED\n");
+ return 0;
}
/**
const fna_vres_id_t vres,
struct timespec *remaining_budget)
{
- return 0;
+ DEBUG("NOT IMPLEMENTED\n");
+ return 0;
}
/**
struct timespec *budget,
struct timespec *period)
{
- return 0;
+ DEBUG("NOT IMPLEMENTED\n");
+ return 0;
}
///////////////////////////////////////////////////////////////////
const int importance,
uint32_t *capacity)
{
- return 0;
+ DEBUG("NOT IMPLEMENTED\n");
+ return 0;
}
/**
const int importance,
int *total_weight)
{
- return 0;
+ DEBUG("NOT IMPLEMENTED\n");
+ return 0;
}
/**
const struct timespec new_budget,
const struct timespec new_period)
{
- return 0;
+ DEBUG("NOT IMPLEMENTED\n");
+ return 0;
}
///////////////////////////////////////////////////////////////////
const void *msg,
const size_t size)
{
- return 0;
+ DEBUG("NOT IMPLEMENTED\n");
+ return 0;
}
/**
const void *msg,
const size_t size)
{
- return 0;
+ DEBUG("send async\n");
+ return 0;
}
/**
size_t *received_bytes,
frsh_network_address_t *from)
{
- return 0;
+ DEBUG("receive sync\n");
+ return 0;
}
/**
size_t *received_bytes,
frsh_network_address_t *from)
{
- return 0;
+ DEBUG("NOT IMPLEMENTED\n");
+ return 0;
}
/**
frsh_endpoint_network_status_t *network_status,
frsh_protocol_status_t *protocol_status)
{
- return 0;
+ DEBUG("NOT IMPLEMENTED\n");
+ return 0;
}
/**
**/
int unix_fna_receive_endpoint_created(const fna_endpoint_data_t *endpoint)
{
- return 0;
+ DEBUG("NOT IMPLEMENTED\n");
+ return 0;
}
/**
frsh_endpoint_network_status_t *network_status,
frsh_protocol_status_t *protocol_status)
{
- return 0;
+ DEBUG("NOT IMPLEMENTED\n");
+ return 0;
}
//////////////////////////////////////////////////////////////////////
const frsh_network_address_t destination,
size_t *max_size)
{
- return 0;
+ DEBUG("NOT IMPLEMENTED\n");
+ return 0;
}
/**
const size_t nbytes,
struct timespec *budget)
{
- return 0;
+ DEBUG("NOT IMPLEMENTED\n");
+ return 0;
}
/**
const struct timespec *budget,
size_t *nbytes)
{
- return 0;
+ DEBUG("NOT IMPLEMENTED\n");
+ return 0;
}
/**
int unix_fna_network_get_min_eff_budget(const frsh_resource_id_t resource_id,
struct timespec *budget)
{
- return 0;
+ DEBUG("NOT IMPLEMENTED\n");
+ return 0;
}
// GLOBAL variable to install the network protocol in FRESCOR
fna_operations_t unix_fna_operations = {
- .fna_init = unix_fna_init,
- .fna_contract_negotiate = unix_fna_contract_negotiate,
- .fna_contract_renegotiate_sync = unix_fna_contract_renegotiate_sync,
- .fna_contract_renegotiate_async = unix_fna_contract_renegotiate_async,
- .fna_vres_get_renegotiation_status = unix_fna_vres_get_renegotiation_status,
- .fna_vres_destroy = unix_fna_vres_destroy,
- .fna_vres_get_contract = unix_fna_vres_get_contract,
- .fna_vres_get_usage = unix_fna_vres_get_usage,
- .fna_vres_get_remaining_budget = unix_fna_vres_get_remaining_budget,
- .fna_vres_get_budget_and_period = unix_fna_vres_get_budget_and_period,
- .fna_resource_get_capacity = unix_fna_resource_get_capacity,
- .fna_resource_get_total_weight = unix_fna_resource_get_total_weight,
- .fna_vres_decrease_capacity = unix_fna_vres_decrease_capacity,
- .fna_send_sync = unix_fna_send_sync,
- .fna_send_async = unix_fna_send_async,
- .fna_receive_sync = unix_fna_receive_sync,
- .fna_receive_async = unix_fna_receive_async,
- .fna_send_endpoint_get_status = unix_fna_send_endpoint_get_status,
- .fna_receive_endpoint_created = unix_fna_receive_endpoint_created,
- .fna_receive_endpoint_get_status = unix_fna_receive_endpoint_get_status,
- .fna_network_get_max_message_size = unix_fna_network_get_max_message_size,
- .fna_network_bytes_to_budget = unix_fna_network_bytes_to_budget,
- .fna_network_budget_to_bytes = unix_fna_network_budget_to_bytes,
- .fna_network_get_min_eff_budget = unix_fna_network_get_min_eff_budget
+ .fna_init = unix_fna_init,
+ .fna_contract_negotiate = unix_fna_contract_negotiate,
+ .fna_contract_renegotiate_sync = unix_fna_contract_renegotiate_sync,
+ .fna_contract_renegotiate_async = unix_fna_contract_renegotiate_async,
+ .fna_vres_get_renegotiation_status = unix_fna_vres_get_renegotiation_status,
+ .fna_vres_destroy = unix_fna_vres_destroy,
+ .fna_vres_get_contract = unix_fna_vres_get_contract,
+ .fna_vres_get_usage = unix_fna_vres_get_usage,
+ .fna_vres_get_remaining_budget = unix_fna_vres_get_remaining_budget,
+ .fna_vres_get_budget_and_period = unix_fna_vres_get_budget_and_period,
+ .fna_resource_get_capacity = unix_fna_resource_get_capacity,
+ .fna_resource_get_total_weight = unix_fna_resource_get_total_weight,
+ .fna_vres_decrease_capacity = unix_fna_vres_decrease_capacity,
+ .fna_send_sync = unix_fna_send_sync,
+ .fna_send_async = unix_fna_send_async,
+ .fna_receive_sync = unix_fna_receive_sync,
+ .fna_receive_async = unix_fna_receive_async,
+ .fna_send_endpoint_get_status = unix_fna_send_endpoint_get_status,
+ .fna_receive_endpoint_created = unix_fna_receive_endpoint_created,
+ .fna_receive_endpoint_get_status = unix_fna_receive_endpoint_get_status,
+ .fna_network_get_max_message_size = unix_fna_network_get_max_message_size,
+ .fna_network_bytes_to_budget = unix_fna_network_bytes_to_budget,
+ .fna_network_budget_to_bytes = unix_fna_network_budget_to_bytes,
+ .fna_network_get_min_eff_budget = unix_fna_network_get_min_eff_budget
};
extern fna_operations_t unix_fna_operations;
+/**
+ * unix addresses:
+ *
+ * As we are in the same node the network address will be always 0.
+ * The stream_ids 0 .. MX_UNIX_STREAM_IDS-1 are statically mapped in the
+ * following table to UNIX pathnames.
+ *
+ **/
+#define MX_UNIX_STREAM_IDS 6
+extern char *the_unix_stream_ids[MX_UNIX_STREAM_IDS];
+
#endif // _UNIX_FNA_H_
#include <time.h> // for timespec
#include "frsh_core.h" // for frsh_contract_set_xxx
-#include "frsh_core_types.h" // for FRSH_RESOURCE_ID_DEFAULT
+#include "frsh_core_types.h" // for FRSH_NETWORK_ID_DEFAULT
#include "frsh_distributed_types.h" // for frsh_network_address_t, frsh_stream_id_t
#include "fna.h" // for fna_vres_id_t
printf("--------------------------------------------------\n");
printf("1.- fna_init\n");
printf("--------------------------------------------------\n");
- err = rtep_fna_operations.fna_init(FRSH_RESOURCE_ID_DEFAULT);
+ err = rtep_fna_operations.fna_init(FRSH_NETWORK_ID_DEFAULT);
assert(err == 0);
printf("--------------------------------------------------\n");
--- /dev/null
+include ../../config.mk
+include ../../rules.mk
+
+CFLAGS += -I$(FNA_PATH)/src_unix/
+LDFLAGS += -L$(FNA_PATH)/lib -lunixfna -L$(FRSH_PATH)/lib -lfrsh -L$(FOSA_PATH)/lib -lfosa_$(PLATFORM) -lm -lfna
\ No newline at end of file
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h> /* atoi */
+#include <unistd.h> /* sleep */
+#include <assert.h>
+#include <string.h> /* memset */
+
+#include <sys/socket.h>
+#include <sys/un.h> /* struct sockaddr_un */
+
+#include "frsh_core.h" // for frsh_contract_set_xxx
+#include "frsh_core_types.h" // for FRSH_NETWORK_ID_DEFAULT
+#include "frsh_distributed_types.h" // for frsh_network_address_t, frsh_stream_id_t
+
+#include "fna.h" // for fna_vres_id_t
+#include "unix_fna.h" // for unix_fna_operations
+
+
+void sender(void);
+void receiver(void);
+
+int main (int argc, char **argv)
+{
+ int err;
+
+ if (argc != 2) {
+ printf("please provide the node to execute:\n");
+ printf(" $./mprogram 0 (sender)\n");
+ printf(" $./mprogram 1 (receiver)\n");
+ return -1;
+ }
+
+ err = unix_fna_operations.fna_init(FRSH_NETWORK_ID_DEFAULT);
+ assert(err == 0);
+
+ switch(atoi(argv[1])) {
+ case 0:
+ sender();
+ break;
+ case 1:
+ receiver();
+ break;
+ default:
+ printf("wrong node number\n");
+ return -1;
+ }
+
+ unlink(the_unix_stream_ids[0]);
+ unlink(the_unix_stream_ids[1]);
+
+ return 0;
+}
+
+void sender(void)
+{
+ int err, i;
+
+ fna_endpoint_data_t endpoint;
+ frsh_stream_id_t receiver_port;
+ char buffer[100];
+ size_t size;
+
+ printf("I am the sender\n");
+
+ receiver_port = 0; /* statically configured to the_unix_stream_ids[0] */
+
+ endpoint.endpoint_type = FRSH_SEND_ENDPOINT_TYPE;
+ endpoint.vres = 0;
+ endpoint.is_bound = true;
+ endpoint.destination = 0; /* only for send_endpoints */
+ endpoint.resource_id = FRSH_NETWORK_ID_DEFAULT;
+ endpoint.stream_id = receiver_port;
+
+ for(i=0; i<10; i++) {
+ sleep(1);
+ size = snprintf(buffer, sizeof(buffer), "hello world %d", i);
+
+ err = unix_fna_operations.fna_send_async(&endpoint,
+ buffer,
+ size);
+ assert (err == 0);
+
+ printf("sender : sent %s\n", buffer);
+ }
+
+ printf("Sender done\n");
+}
+
+void receiver(void)
+{
+ int err, i;
+ fna_endpoint_data_t endpoint;
+ frsh_network_address_t sender_addr;
+ frsh_stream_id_t sender_port;
+ char buffer[100];
+ size_t received_bytes;
+
+ printf("I am the receiver\n");
+
+ sender_port = 1;
+
+ endpoint.endpoint_type = FRSH_RECEIVE_ENDPOINT_TYPE;
+ endpoint.is_bound = false;
+ endpoint.resource_id = FRSH_NETWORK_ID_DEFAULT;
+ endpoint.stream_id = sender_port;
+
+ for(i=0; i<10; i++) {
+ err = unix_fna_operations.fna_receive_sync(&endpoint,
+ buffer,
+ 100,
+ &received_bytes,
+ &sender_addr);
+ assert (err == 0);
+
+ buffer[received_bytes] = '\0';
+
+ printf("receiver : received %s\n", buffer);
+ }
+
+ printf("Receiver done\n");
+}
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h> /* atoi */
+#include <unistd.h> /* sleep */
+#include <assert.h>
+#include <string.h> /* memset */
+
+#include <sys/socket.h>
+#include <sys/un.h> /* struct sockaddr_un */
+
+#define SENDER_PATH "/tmp/sender_addr"
+#define RECEIVER_PATH "/tmp/receiver_addr"
+
+void sender(void);
+void receiver(void);
+
+int main (int argc, char **argv)
+{
+ if (argc != 2) {
+ printf("please provide the node to execute:\n");
+ printf(" $./mprogram 0 (sender)\n");
+ printf(" $./mprogram 1 (receiver)\n");
+ return -1;
+ }
+
+ switch(atoi(argv[1])) {
+ case 0:
+ sender();
+ break;
+ case 1:
+ receiver();
+ break;
+ default:
+ printf("wrong node number\n");
+ return -1;
+ }
+
+ unlink(SENDER_PATH);
+ unlink(RECEIVER_PATH);
+
+ return 0;
+}
+
+void sender(void)
+{
+ int sock, err, i;
+ struct sockaddr_un sender_addr, receiver_addr;
+ char buffer[100];
+ size_t size;
+ ssize_t sent_bytes;
+
+ printf("I am the sender\n");
+
+ err = sock = socket(AF_UNIX, SOCK_DGRAM, 0);
+ assert(err >= 0);
+
+ memset(&sender_addr, 0, sizeof(sender_addr));
+ sender_addr.sun_family = AF_UNIX;
+ strcpy(sender_addr.sun_path, SENDER_PATH);
+
+ err = bind(sock, (struct sockaddr *)&sender_addr, sizeof(sender_addr));
+ assert(err >= 0);
+
+ memset(&receiver_addr, 0, sizeof(receiver_addr));
+ receiver_addr.sun_family = AF_UNIX;
+ strcpy(receiver_addr.sun_path, RECEIVER_PATH);
+
+ for(i=0; i<10; i++) {
+ sleep(1);
+ size = snprintf(buffer, sizeof(buffer), "hello world %d", i);
+ sent_bytes = sendto(sock,
+ buffer,
+ size,
+ 0,
+ (struct sockaddr *) &receiver_addr,
+ sizeof(receiver_addr));
+
+ assert(sent_bytes >= 0);
+
+ printf("sender : sent %s\n", buffer);
+ }
+
+ close(sock);
+ printf("Sender done\n");
+}
+
+void receiver(void)
+{
+ int sock, err, i;
+ struct sockaddr_un sender_addr, receiver_addr;
+ char buffer[100];
+ ssize_t received_bytes;
+ socklen_t from_len;
+
+ printf("I am the receiver\n");
+
+ err = sock = socket(AF_UNIX, SOCK_DGRAM, 0);
+ assert(err >= 0);
+
+ memset(&receiver_addr, 0, sizeof(receiver_addr));
+ receiver_addr.sun_family = AF_UNIX;
+ strcpy(receiver_addr.sun_path, RECEIVER_PATH);
+
+ err = bind(sock, (struct sockaddr *)&receiver_addr, sizeof(receiver_addr));
+ assert(err >= 0);
+
+ for(i=0; i<10; i++) {
+
+ sleep(5);
+
+ from_len = sizeof(sender_addr);
+ received_bytes = recvfrom(sock,
+ buffer,
+ sizeof(buffer),
+ 0,
+ (struct sockaddr *)&sender_addr,
+ &from_len);
+
+ assert(received_bytes >= 0);
+
+ buffer[received_bytes] = '\0';
+ printf("receiver : received %s\n", buffer);
+ }
+
+ close(sock);
+ printf("receiver done\n");
+}