--- /dev/null
+/**
+ * \file distributed.c
+ *
+ * This a test application that:
+ * - creates vres
+ * - creates send and receive endpoint
+ * - binds that endpoint to vres
+ * - in cycle (NUM loops) sends messages in separate thread and
+ * prints send time
+ * - receives messages in separate receiver thread
+ * - destroys vres
+ *
+ */
+#include "frsh.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <pthread.h>
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#define NUM 10
+#define PORT 65111
+#define PROTO FRSH_NETPF_FWP
+
+int exit_flag = 0;
+
+void* sender()
+{
+ frsh_send_endpoint_t sepoint;
+ frsh_vres_id_t vres;
+ frsh_send_endpoint_protocol_info_t send_pinfo;
+ frsh_contract_t contract;
+ frsh_rel_time_t budget, period;
+ char msg1[10];
+ int count, ret;
+ /*struct timespec sendtime;*/
+
+ send_pinfo.body = NULL;
+ if (frsh_send_endpoint_create(PROTO, inet_addr("127.0.0.1"), PORT,
+ send_pinfo, &sepoint)< 0) {
+ return NULL;
+ }
+
+ /* Contract negotiation */
+ ret = frsh_contract_init(&contract);
+ if (ret) PERROR_AND_EXIT(ret, "frsh_contract_init");
+
+ budget = fosa_msec_to_rel_time(100);
+ period = fosa_msec_to_rel_time(1000);
+ ret = frsh_contract_set_basic_params(&contract,
+ &budget,
+ &period,
+ FRSH_WT_BOUNDED,
+ FRSH_CT_REGULAR);
+ if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_basic_params");
+ ret = frsh_contract_set_resource_and_label(&contract,FRSH_RT_NETWORK,
+ FRSH_NETPF_FWP,
+ "fwp_cont1");
+ if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_resource_and_label");
+
+ ret = frsh_contract_negotiate(&contract, &vres);
+ if (ret) PERROR_AND_EXIT(ret, "frsh_contract_negotiate");
+
+ printf("Send endpoint created\n");
+ frsh_send_endpoint_bind(vres, sepoint);
+ printf("Send endpoint bounded\n");
+
+ sleep(2);
+ //fwp_set_rt_prio(90);
+
+ count = 0;
+ while (count < NUM){
+ count++;
+ sprintf(msg1,"msg%d",count);
+ frsh_send_async(sepoint, msg1, sizeof(msg1));
+
+ printf("%s sent\n",msg1);
+ /*clock_gettime(CLOCK_MONOTONIC, &sendtime);
+ FWP_DEBUG("Sent %d: sec = %ld nsec = %ld \n", count,
+ sendtime.tv_sec, sendtime.tv_nsec);
+ usleep(1000);*/
+ }
+
+ while (!(exit_flag)) {
+ sleep(1);
+ }
+
+ return NULL;
+}
+
+void* receiver()
+{
+ size_t len;
+ char buffer[30];
+ frsh_receive_endpoint_t repoint;
+ int count;
+ struct timespec recvtime;
+ frsh_network_address_t from;
+ frsh_receive_endpoint_protocol_info_t recv_pinfo;
+ frsh_endpoint_queueing_info_t qinfo;
+ frsh_resource_id_t resource_id;
+ frsh_stream_id_t stream;
+ frsh_endpoint_queueing_info_t queueing_info;
+ frsh_receive_endpoint_protocol_info_t protocol_info;
+
+ recv_pinfo.body = NULL;
+ /* local_addr should be handled when creating socket */
+// if (frsh_receive_endpoint_create(PROTO, PORT, qinfo, recv_pinfo,
+ if (frsh_receive_endpoint_create(PROTO, 0, qinfo, recv_pinfo,
+ &repoint) != 0){
+ return NULL;
+ }
+ printf("Receive endpoint created\n");
+
+ frsh_receive_endpoint_get_params(repoint,&resource_id,&stream,&queueing_info,&protocol_info);
+
+ printf("Receive port :%d\n",stream);
+
+
+ for (count = 1; count <= NUM; count++) {
+
+ if ((frsh_receive_sync(repoint, buffer, sizeof(buffer), &len,
+ &from))){
+ perror("Error while receiving data");
+ return NULL;
+ }
+ else printf("Received - %s\n", buffer);
+
+ clock_gettime(CLOCK_MONOTONIC, &recvtime);
+ printf("Received %d: sec = %ld nsec = %ld \n", count,
+ recvtime.tv_sec, recvtime.tv_nsec);
+ }
+
+ exit_flag = 1;
+
+ return NULL;
+}
+
+int main()
+{
+ pthread_attr_t thattr;
+ pthread_t thread;
+ int ret;
+
+ printf("Start\n");
+ ret = frsh_init();
+ if (ret) PERROR_AND_EXIT(ret, "frsh_init");
+
+ /*if (frsh_distributed_init()) {
+ fprintf(stderr,"FRSH distributed modul initialization failed.\n");
+ }*/
+
+ pthread_attr_init(&thattr);
+ pthread_create(&thread, &thattr, receiver, NULL);
+ pthread_create(&thread, &thattr, sender, NULL);
+ pthread_join(thread, (void**) NULL);
+
+ printf("Test PASSED!\n");
+ return 0;
+}