Repository navigation
Expand file tree
/
Copy pathhandler_lib.c
More file actions
198 lines (153 loc) · 5.84 KB
/
Copy pathhandler_lib.c
File metadata and controls
198 lines (153 loc) · 5.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#include <unistd.h>
#include <stdlib.h>
#include <inttypes.h>
#include <time.h>
#include <stdio.h>
#include <errno.h>
#include <sys/time.h>
#include "handler_lib.h"
static uint32_t unique_handler_id = 0;
uint32_t xen_shm_handler_get_id(void);
uint32_t
xen_shm_handler_get_id(void) {
return unique_handler_id++;
}
void* xen_shm_handler_ping_client (struct xen_shm_handler_data* data) {
struct timespec in_stamp;
struct timespec out_stamp;
int i;
ssize_t len;
uint8_t noise[PING_PACKET_SIZE];
while(!data->stop) {
clock_gettime(CLOCK_REALTIME, &out_stamp);
for (i = 0; i < PING_SERIES_LENGTH; ++i) {
len = xen_shm_pipe_write_all(data->send_fd, noise, PING_PACKET_SIZE);
if (len < 0) {
printf("Unable to send\n");
perror("xen_shm_pipe_write_all");
return NULL;
}
xen_shm_pipe_flush(data->receive_fd);
len = xen_shm_pipe_read_all(data->receive_fd, noise, PING_PACKET_SIZE);
if (len < 0) {
printf("Unable to receive\n");
perror("xen_shm_pipe_read_all");
return NULL;
}
xen_shm_pipe_flush(data->receive_fd);
}
clock_gettime(CLOCK_REALTIME, &in_stamp);
printf("Sent at %ld.%09ld\n", out_stamp.tv_sec, out_stamp.tv_nsec);
printf("Received at %ld.%09ld\n", in_stamp.tv_sec, in_stamp.tv_nsec);
}
return NULL;
}
void* xen_shm_handler_ping_server (struct xen_shm_handler_data* data) {
uint8_t noise[PING_PACKET_SIZE];
ssize_t len;
while (!data->stop) {
len = xen_shm_pipe_read_all(data->receive_fd, &noise, PING_PACKET_SIZE);
if (len < 0) {
printf("Unable to receive\n");
perror("xen_shm_pipe_read_all");
return NULL;
}
xen_shm_pipe_flush(data->receive_fd);
len = xen_shm_pipe_write_all(data->send_fd, &noise, PING_PACKET_SIZE);
if (len < 0) {
printf("Unable to send\n");
perror("xen_shm_pipe_write_all");
return NULL;
}
xen_shm_pipe_flush(data->send_fd);
}
return NULL;
}
void* xen_shm_handler_sender(struct xen_shm_handler_data* data) {
struct xen_shm_handler_transfert* trans_data;
ssize_t ret;
struct timeval in_stamp;
struct timeval out_stamp;
uint64_t byte_counter;
uint64_t print_threashold;
uint64_t last_print_s;
uint32_t transfert_id;
uint64_t delay;
uint8_t* buffer;
double bandwidth;
trans_data = (struct xen_shm_handler_transfert*) data->private_data;
buffer = malloc(sizeof(uint8_t)*trans_data->buffer_len);
transfert_id = xen_shm_handler_get_id();
byte_counter = 0;
bandwidth = 2000;
print_threashold = (uint64_t) (bandwidth * 1000000)/4;
gettimeofday(&in_stamp , NULL);
last_print_s = (uint64_t) in_stamp.tv_sec;
while(!data->stop) {
ret = xen_shm_pipe_write_all(data->send_fd, buffer, trans_data->buffer_len);
if(ret < 0) {
printf("transfert %"PRIu32" error - ", transfert_id);
perror("pipe write all");
return NULL;
}
byte_counter+=trans_data->buffer_len;
if(trans_data->print_info && byte_counter>print_threashold) {
gettimeofday(&out_stamp , NULL);
delay = ((uint64_t) (out_stamp.tv_sec - in_stamp.tv_sec))*1000000 + (uint64_t) (out_stamp.tv_usec - in_stamp.tv_usec);
bandwidth = (((double) byte_counter)*8)/((double) delay);
print_threashold =(uint64_t) ((bandwidth * 1000000)/4);
if((uint64_t) out_stamp.tv_sec > last_print_s) {
printf("%"PRIu32", %"PRIu64", %"PRIu64", s, %f, Mbps\n",transfert_id,byte_counter ,((uint64_t) out_stamp.tv_sec)*1000 + ((uint64_t) out_stamp.tv_usec)/1000, bandwidth);
last_print_s = (uint64_t) out_stamp.tv_sec;
}
byte_counter = 0;
in_stamp = out_stamp;
}
}
free(buffer);
return NULL;
}
void* xen_shm_handler_receiver(struct xen_shm_handler_data* data) {
struct xen_shm_handler_transfert* trans_data;
ssize_t ret;
struct timeval in_stamp;
struct timeval out_stamp;
uint64_t byte_counter;
uint64_t print_threashold;
uint64_t last_print_s;
uint32_t transfert_id;
uint64_t delay;
uint8_t* buffer;
double bandwidth;
trans_data = (struct xen_shm_handler_transfert*) data->private_data;
buffer = malloc(sizeof(uint8_t)*trans_data->buffer_len);
transfert_id = xen_shm_handler_get_id();
byte_counter = 0;
bandwidth = 2000;
print_threashold = (uint64_t) (bandwidth * 1000000)/4;
gettimeofday(&in_stamp , NULL);
last_print_s = (uint64_t) in_stamp.tv_sec;
while(!data->stop) {
ret = xen_shm_pipe_read_all(data->receive_fd, buffer, trans_data->buffer_len);
if(ret < 0) {
printf("transfert %"PRIu32" error - ", transfert_id);
perror("pipe read all");
return NULL;
}
byte_counter+=trans_data->buffer_len;
if(trans_data->print_info && byte_counter>print_threashold) {
gettimeofday(&out_stamp , NULL);
delay = ((uint64_t) (out_stamp.tv_sec - in_stamp.tv_sec))*1000000 + (uint64_t) (out_stamp.tv_usec - in_stamp.tv_usec);
bandwidth = (((double) byte_counter)*8)/((double) delay);
print_threashold =(uint64_t) ((bandwidth * 1000000)/4);
if((uint64_t) out_stamp.tv_sec > last_print_s) {
printf("%"PRIu32", %"PRIu64", %"PRIu64", r, %f, Mbps\n",transfert_id,byte_counter ,((uint64_t) out_stamp.tv_sec)*1000 + ((uint64_t) out_stamp.tv_usec)/1000, bandwidth);
last_print_s = (uint64_t) out_stamp.tv_sec;
}
byte_counter = 0;
in_stamp = out_stamp;
}
}
free(buffer);
return NULL;
}