unsigned opt_jitter = 0;
char *opt_output = "delay_stats";
unsigned opt_count_sec = 0;
-unsigned opt_def_bandwidth = 200;
+unsigned opt_def_bandwidth = 50;
unsigned opt_def_period_msec = 0;
int opt_granularity_usec = MIN_GRANULARITY;
bool opt_wait_for_queue_is_full; /* Don't gather any statistics until any queue is full */
bool some_queue_is_full = false;
struct timespec reset_timestamp;
+bool some_contract_not_accepted = false;
+
/* Locked when some queue is full to prevent multiple resets of
statstics. */
pthread_mutex_t queue_full_mutex = PTHREAD_MUTEX_INITIALIZER;
int ac_sockfd[AC_NUM];
struct receiver {
+ bool valid;
pthread_t thread;
unsigned received, last_received;
};
#ifndef WITH_FWP
struct sockaddr_in rem_addr;
#else
+ fwp_contract_d_t contract_send;
+ fwp_contract_d_t contract_resp;
fwp_endpoint_d_t endpoint;
fwp_endpoint_d_t resp_endpoint;
fwp_vres_d_t vres;
/* Interrupt all receivers */
#ifdef WITH_FWP
for (i=0; i < nr_streams; i++) {
- pthread_kill(streams[i].receiver.thread, SIGUSR1);
- }
+ if (streams[i].receiver.valid) pthread_kill(streams[i].receiver.thread, SIGUSR1);
+ if (streams[i].contract_send) fwp_contract_cancel(streams[i].contract_send);
+ if (streams[i].contract_resp)fwp_contract_cancel(streams[i].contract_resp);
+ }
#else
for (i=0; i < AC_NUM; i++) {
pthread_kill(receivers[i].thread, SIGUSR1);
static int negotiate_contract_for_stream_fwp(struct stream *stream)
{
fwp_contract_t contract;
- fwp_contract_d_t contract_d;
fwp_vres_d_t vres2;
int ret;
contract.period_usec = stream->period_usec;
contract.deadline_usec = 3*stream->period_usec;
- contract_d = fwp_contract_create(&contract);
- ret = fwp_contract_negotiate(contract_d, &stream->vres);
+ stream->contract_send = fwp_contract_create(&contract);
+ ret = fwp_contract_negotiate(stream->contract_send, &stream->vres);
if (ret != 0) {
- fprintf(stderr, "Send contract was not accepted\n");
- exit(1);
+ stream->contract_send = NULL;
+ fprintf(stderr, "Send contract was not accepted\n\n\n");
+ return ret;
}
/* Contract for server->client stream */
contract.period_usec = stream->period_usec;
contract.deadline_usec = 3*stream->period_usec;
- contract_d = fwp_contract_create(&contract);
- ret = fwp_contract_negotiate(contract_d, &vres2);
+ stream->contract_resp = fwp_contract_create(&contract);
+ ret = fwp_contract_negotiate(stream->contract_resp, &vres2);
if (ret != 0) {
- fprintf(stderr, "Receive contract was not accepted\n");
- exit(1);
+ stream->contract_resp = NULL;
+ fprintf(stderr, "Receive contract was not accepted\n\n\n");
+ return ret;
}
/* We don't use the vres at server, since the server doesn't
unsigned int port;
fwp_endpoint_get_params(stream->resp_endpoint, NULL, &port, NULL);
stream->resp_port = port;
- printf("resp_port = %d\n", port);
ret = pthread_create(&stream->receiver.thread, NULL, receiver, (void*)stream);
if (ret) {
perror("Error while creating receiver\n");
exit(1);
}
+ stream->receiver.valid = true;
}
else {
char str[100];
} else {
char buf[200];
stream_to_text(buf, sizeof(buf), stream, 0);
- fprintf(stderr, "Contract hasn't been accepted: %s\n", buf);
+ fprintf(stderr, "Contract hasn't been accepted:\n%s\n\n", buf);
stream->bandwidth_bps = 0;
+ some_contract_not_accepted = true;
}
}
for (i = 0; i <= nr_streams; i++) {
if (i>0) s = &streams[i-1];
- y=i+3;
+ y=i;
x=0;
addfield("Stream", "%d", i);
addfield("Bandwidth", "%s", bandwidth_to_text(s1, s->bandwidth_bps));
addfield("Period ", "%s", usec_to_text(s1, s->period_usec));
addfield("AC ", "%s", ac_to_text[s->ac]);
addfield("Worst-case delay", "%s", usec_to_text(s1, s->wc_delay));
- addfield("Received responses", "%d", s->received);
+ addfield("Received responses", "%lld", s->received);
}
refresh();
}
fprintf(stderr, "Error while creating receiver %d\n",rc);
return 1;
}
+ receivers[ac].valid = true;
}
#endif
}
}
- init_gui();
-
- seconds = 0;
- while (!exit_flag) {
- sleep(1);
- seconds++;
- print_status(seconds);
- if (seconds == opt_count_sec)
- stopper();
+ if (some_contract_not_accepted) {
+ stopper();
+ } else {
+ init_gui();
+
+ seconds = 0;
+ while (!exit_flag) {
+ sleep(1);
+ seconds++;
+ print_status(seconds);
+ if (seconds == opt_count_sec)
+ stopper();
+ }
}
#ifdef WITH_FWP
endwin();
+ fwp_done();
#endif
fprintf(stderr, "\nWaiting for threads to finish\n");
wait_for_all_threads_to_finish();