forked from maratishe/e2eprobe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprobe.udp.pathchirp.tx.c
More file actions
77 lines (68 loc) · 2.31 KB
/
probe.udp.pathchirp.tx.c
File metadata and controls
77 lines (68 loc) · 2.31 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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <unistd.h>
#include <float.h>
#include <math.h>
#include <stdarg.h>
#include <time.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
double getime() {
struct timeval tv;
gettimeofday( &tv, NULL);
return ( double)( tv.tv_sec + ( ( double) tv.tv_usec) / 1000000.0);
}
void flog( const char *file, const char *msg) {
FILE *out = fopen( file, "a");
double time = getime();
fprintf( out, "times=%d,timeus=%d,%s\n", ( int)time, ( int)( 1000000 * ( time - ( int)time)), msg);
fclose( out);
}
void flog2( FILE *file, const char *msg) {
double time = getime();
fprintf( file, "times=%d,timeus=%d,%s\n", ( int)time, ( int)( 1000000 * ( time - ( int)time)), msg);
}
int main( int argc, char **argv) {
int status, limit, i, pos;
if ( argc != 7) { printf( "bg.udp.tx [1 rip][2 rport][3 psize][4 probesize][5 pspace][6 pspaceratio]\n"); exit( 1); }
char *rip = argv [ 1];
int rport = atoi( argv[ 2]);
int psize = atoi( argv[ 3]);
int probesize = atoi( argv[ 4]); // usec
int pspace = atoi( argv[ 5]);
double pspaceratio = atof( argv[ 6]);
struct sockaddr_in addrout; // the address out
addrout.sin_family = AF_INET;
addrout.sin_port = htons( rport);
inet_aton( rip, &addrout.sin_addr);
int sock = socket( AF_INET, SOCK_DGRAM, 0);
int flags = fcntl( sock, F_GETFL); //modif 3 lines from here
flags |= O_NONBLOCK;
fcntl( sock, F_SETFL, flags);
// wait for startfile to appear
//struct stat finfo; srand( time( NULL));
//while ( stat( startfile, &finfo) != 0) usleep( 50000 + rand() % 50000);
//flog2( out, "type=start");
int id = 0; limit = 0;
char buf[ psize + 2]; for ( i = 0; i < psize + 2; i++) buf[ i] = '\0';
double time, ltime, start; start = getime(); ltime = start;
char msg[ 128]; pos = 0;
for ( pos = 0; pos < probesize; pos++) {
double before = getime(); double now = before;
sprintf( buf, "%d", pos, 0, 0);
status = sendto( sock, buf, psize, 0, ( struct sockaddr *)&addrout, sizeof( struct sockaddr_in));
while ( 1000000.0 * ( now - before) < pspace) now = getime();
ltime = time; pspace = ( int)( ( ( double)pspace) / pspaceratio);
}
sleep( 1);
close( sock);
}