--- /dev/null
+/**
+ * \file fwpsender.c
+ *
+ */
+#include <frsh.h>
+#include "test_config.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <pthread.h>
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+char msg[MSGBUFFSIZE];
+
+frsh_resource_id_t resource_id = TEST_RESOURCE_ID;
+frsh_stream_id_t stream_id = TEST_STREAM_ID;
+long int num_msg = TEST_NUM_MSG;
+size_t msg_size = MSGBUFFSIZE;
+
+int exit_flag = 0;
+int node_id = 0;
+
+inline void timespec_sub(struct timespec *diff, const struct timespec *left,
+ const struct timespec *right)
+{
+ diff->tv_sec = left->tv_sec - right->tv_sec;
+ diff->tv_nsec = left->tv_nsec - right->tv_nsec;
+
+ if (diff->tv_nsec < 0){
+ --diff->tv_sec;
+ diff->tv_nsec += 1000000000;
+ }
+}
+
+void* sender(void * arg)
+{
+ 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;
+ int count, ret;
+ struct timespec sendtime;
+
+ send_pinfo.body = NULL;
+ if (frsh_send_endpoint_create(resource_id, node_id, stream_id,
+ send_pinfo, &sepoint)< 0) {
+ return NULL;
+ }
+
+ /* Contract negotiation */
+ ret = frsh_contract_init(&contract);
+ if (ret) PERROR_AND_EXIT(ret, "frsh_contract_init");
+
+ frsh_network_bytes_to_budget(resource_id, msg_size, &budget);
+ 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,
+ resource_id, "net_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 = 1;
+ while (count != num_msg) {
+ count++;
+ clock_gettime(CLOCK_MONOTONIC, &sendtime);
+ sprintf(msg,"msg%d-%ld-%ld", count,
+ sendtime.tv_sec, sendtime.tv_nsec);
+ frsh_send_async(sepoint, msg, msg_size);
+
+ printf("%s sent\n",msg);
+ }
+
+ /* TODO: destroy vres and send enpoint */
+
+ while (!(exit_flag)) {
+ sleep(1);
+ }
+
+ return NULL;
+}
+
+void* receiver()
+{
+ size_t len;
+ frsh_receive_endpoint_t repoint;
+ int count;
+ frsh_network_address_t from;
+ frsh_receive_endpoint_protocol_info_t recv_pinfo;
+ frsh_endpoint_queueing_info_t qinfo;
+ struct timespec recvtime;
+ struct timespec sendtime;
+ struct timespec difftime;
+
+ recv_pinfo.body = NULL;
+ /* local_addr should be handled when creating socket */
+ if (frsh_receive_endpoint_create(resource_id, stream_id, qinfo, recv_pinfo,
+ &repoint) != 0){
+ return NULL;
+ }
+ printf("Receive endpoint created\n");
+
+ count = 1;
+ while (count != num_msg){
+ count++;
+ if ((frsh_receive_sync(repoint, msg, msg_size, &len,
+ &from))) {
+ perror("Error while receiving data");
+ return NULL;
+ }
+
+ sscanf(msg,"msg%d-%ld-%ld", &count,
+ &sendtime.tv_sec, &sendtime.tv_nsec);
+ clock_gettime(CLOCK_MONOTONIC, &recvtime);
+ timespec_sub(&difftime, &recvtime, &sendtime);
+ printf("Received - %s\n time= %ld us", msg,
+ difftime.tv_nsec / 1000);
+ }
+
+ /* TODO: destroy vres and send enpoint */
+
+ return NULL;
+}
+
+int main(int argc, char* argv[])
+{
+ pthread_attr_t thattr;
+ pthread_t thread;
+ int opt;
+ int ret;
+
+ opterr = 0;
+ while ((opt = getopt (argc, argv, "n:p:s:m:")) != -1) {
+
+ switch (opt) {
+ case 'n':
+ node_id = inet_addr(optarg);
+ break;
+ case 'p':
+ stream_id = atoi(optarg);
+ break;
+ case 'm':
+ num_msg = atoi(optarg);
+ break;
+ case 's':
+ msg_size = atoi(optarg);
+ break;
+ case '?':
+ printf("Usage: %s -n node_id -p stream_id"
+ "-m num_msg -s msg_size\n",
+ argv[0]);
+ }
+ }
+
+ ret = frsh_init();
+ if (ret) PERROR_AND_EXIT(ret, "frsh_init");
+
+ pthread_attr_init(&thattr);
+ pthread_create(&thread, &thattr, sender, NULL);
+ pthread_join(thread, (void**) NULL);
+
+ printf("Test PASSED!\n");
+ return 0;
+}
--- /dev/null
+#include <frsh.h>
+#include "test_config.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <pthread.h>
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+char msg[MSGBUFFSIZE];
+
+frsh_resource_id_t resource_id = TEST_RESOURCE_ID;
+frsh_stream_id_t stream_id = TEST_STREAM_ID;
+long int num_msg = TEST_NUM_MSG;
+size_t msg_size = MSGBUFFSIZE;
+
+frsh_send_endpoint_t sepoint;
+frsh_vres_id_t vres;
+
+void
+create_send_endpoint(frsh_network_address_t node_id, frsh_stream_id_t stream_id)
+{
+ frsh_send_endpoint_protocol_info_t send_pinfo;
+ frsh_contract_t contract;
+ frsh_rel_time_t budget, period;
+ int ret;
+
+ send_pinfo.body = NULL;
+ if (frsh_send_endpoint_create(resource_id, node_id, stream_id,
+ send_pinfo, &sepoint) < 0) {
+ return;
+ }
+
+ /* Contract negotiation */
+ ret = frsh_contract_init(&contract);
+ if (ret) PERROR_AND_EXIT(ret, "frsh_contract_init");
+
+ frsh_network_bytes_to_budget(resource_id, msg_size, &budget);
+ 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,
+ resource_id, "net_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");
+}
+
+void* receiver()
+{
+ size_t len;
+ 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;
+ int first = 1;
+
+ recv_pinfo.body = NULL;
+ /* local_addr should be handled when creating socket */
+ if (frsh_receive_endpoint_create(resource_id, stream_id, qinfo, recv_pinfo,
+ &repoint) != 0){
+ return NULL;
+ }
+ printf("Receive endpoint created\n");
+
+ count = 1;
+ while (count != num_msg){
+ count++;
+ if ((frsh_receive_sync(repoint, msg, msg_size, &len,
+ &from))){
+ perror("Error while receiving data");
+ return NULL;
+ }
+
+ if (first) {
+ create_send_endpoint(from, stream_id);
+ first = 0;
+ }
+
+ frsh_send_async(sepoint, msg, msg_size);
+ printf("pong - %s\n", msg);
+ }
+
+ /* TODO: destroy vres and send enpoint */
+
+ return NULL;
+}
+
+int main(int argc, char* argv[])
+{
+ pthread_attr_t thattr;
+ pthread_t thread;
+ int ret;
+ int opt;
+
+ opterr = 0;
+
+ while ((opt = getopt (argc, argv, "p:m:")) != -1) {
+
+ switch (opt) {
+ case 'p':
+ stream_id = atoi(optarg);
+ break;
+ case 'm':
+ num_msg = atoi(optarg);
+ case '?':
+ printf("Usage: %s -p stream_id -m num_msg\n",
+ argv[0]);
+ }
+ }
+
+ ret = frsh_init();
+ if (ret) PERROR_AND_EXIT(ret, "frsh_init");
+
+ pthread_attr_init(&thattr);
+ pthread_create(&thread, &thattr, receiver, NULL);
+ pthread_join(thread, (void**) NULL);
+
+ printf("Test PASSED!\n");
+ return 0;
+}