Commit c12e3e15c41c100a4808087709804fe4baf22ab1
1 parent
bcd0dad561
Exists in
master
RTT client server stringlen fix
Showing 4 changed files with 37 additions and 18 deletions Inline Diff
network/overhead_client.c
View file @
c12e3e1
#include "../rasperf.h" | 1 | 1 | #include "../rasperf.h" | |
#include<stdio.h> | 2 | 2 | #include<stdio.h> | |
#include<stdlib.h> | 3 | 3 | #include<stdlib.h> | |
#include<arpa/inet.h> | 4 | 4 | #include<arpa/inet.h> | |
#include<sys/types.h> | 5 | 5 | #include<sys/types.h> | |
#include<sys/socket.h> | 6 | 6 | #include<sys/socket.h> | |
#include<netdb.h> | 7 | 7 | #include<netdb.h> | |
#include<string.h> | 8 | 8 | #include<string.h> | |
//Macro definitions | 9 | 9 | //Macro definitions | |
#define handle_error(msg) \ | 10 | 10 | #define handle_error(msg) \ | |
do { perror(msg); exit(1);} while(0); | 11 | 11 | do { perror(msg); exit(1);} while(0); | |
#define BACKLOG 50 | 12 | 12 | #define BACKLOG 50 | |
int main(int argc, char*argv[]) | 13 | 13 | int main(int argc, char*argv[]) | |
{ | 14 | 14 | { | |
int socket_fd, rc; | 15 | 15 | int socket_fd, rc; | |
float start_delta = 0, close_delta = 0; | 16 | 16 | float start_delta = 0, close_delta = 0; | |
if(argc<2){ | 17 | 17 | if(argc<2){ | |
handle_error("<usage>:tcp_client <IP address>"); | 18 | 18 | handle_error("<usage>:tcp_client <IP address>"); | |
} | 19 | 19 | } | |
//Retrieve the protocol number mapping | 20 | 20 | //Retrieve the protocol number mapping | |
//from /etc/protocols file | 21 | 21 | //from /etc/protocols file | |
struct protoent *proto_entry; | 22 | 22 | struct protoent *proto_entry; | |
proto_entry = getprotobyname("tcp"); | 23 | 23 | proto_entry = getprotobyname("tcp"); | |
24 | 24 | |||
25 | 25 | |||
//My address information to bind to | 26 | 26 | //My address information to bind to | |
struct sockaddr_in server; | 27 | 27 | struct sockaddr_in server; | |
memset(&server, 0, sizeof(struct sockaddr)); | 28 | 28 | memset(&server, 0, sizeof(struct sockaddr)); | |
server.sin_family = AF_INET; | 29 | 29 | server.sin_family = AF_INET; | |
server.sin_port = htons(8000); | 30 | 30 | server.sin_port = htons(8000); | |
31 | 31 | |||
rc= inet_pton(AF_INET, argv[1], &server.sin_addr); | 32 | 32 | rc= inet_pton(AF_INET, argv[1], &server.sin_addr); | |
if(rc == -1){ | 33 | 33 | if(rc == -1){ | |
handle_error("Address Error"); | 34 | 34 | handle_error("Address Error"); | |
} | 35 | 35 | } | |
time starttime, endtime; | 36 | 36 | time starttime, endtime; | |
//accept incoming connections | 37 | 37 | //accept incoming connections | |
int addr_size = sizeof(struct sockaddr); | 38 | 38 | int addr_size = sizeof(struct sockaddr); | |
int i; | 39 | 39 | int i; | |
int protonum = proto_entry->p_proto; | 40 | 40 | int protonum = proto_entry->p_proto; | |
for(i=1;i<=BACKLOG;i++){ | 41 | 41 | for(i=1;i<=BACKLOG;i++){ | |
getTime(starttime); | 42 | 42 | getTime(starttime); | |
//Open an socket end-point for this TCP Server | 43 | 43 | //Open an socket end-point for this TCP Server | |
if((socket_fd = socket(AF_INET, SOCK_STREAM, protonum))<0){ | 44 | 44 | if((socket_fd = socket(AF_INET, SOCK_STREAM, protonum))<0){ | |
handle_error("Socket Error"); | 45 | 45 | handle_error("Socket Error"); | |
} | 46 | 46 | } | |
if(connect(socket_fd, (struct sockaddr*)&server, sizeof(server))<0){ | 47 | 47 | if(connect(socket_fd, (struct sockaddr*)&server, sizeof(server))<0){ | |
handle_error("Connection Error"); | 48 | 48 | handle_error("Connection Error"); | |
} | 49 | 49 | } | |
/*The end calculated here will miss time taken for ACK K+1 | 50 | 50 | /*The end calculated here will miss time taken for ACK K+1 | |
from the client. And so we have to one way delay | 51 | 51 | from the client. And so we have to one way delay | |
measured using another experiment*/ | 52 | 52 | measured using another experiment*/ | |
getTime(endtime); | 53 | 53 | getTime(endtime); | |
54 | 54 | |||
//Calculate connection overhead client | 55 | 55 | //Calculate connection overhead client | |
start_delta+=diff(endtime,starttime); | 56 | 56 | start_delta+=diff(endtime,starttime); | |
57 | 57 | int z; /* Status code */ | ||
58 | int s; /* Socket s */ | |||
59 | struct linger so_linger; | |||
60 | ||||
61 | so_linger.l_onoff = 1; | |||
62 | so_linger.l_linger = 0; | |||
63 | /*z = setsockopt(socket_fd, | |||
64 | SOL_SOCKET, | |||
65 | SO_LINGER, | |||
66 | &so_linger, | |||
67 | sizeof so_linger); | |||
68 | ||||
69 | if ( z ) | |||
70 | perror("setsockopt(2)"); | |||
71 | */ | |||
getTime(starttime); | 58 | 72 | getTime(starttime); | |
shutdown(socket_fd, SHUT_RDWR); | 59 | 73 | shutdown(socket_fd, SHUT_RDWR); | |
74 | //close(socket_fd); | |||
getTime(endtime); | 60 | 75 | getTime(endtime); | |
61 | 76 | |||
//Calculate connection overhead server side | 62 | 77 | //Calculate connection overhead server side | |
close_delta+=diff(endtime,starttime); | 63 | 78 | close_delta+=diff(endtime,starttime); |
network/random_str.c
View file @
c12e3e1
#include<stdio.h> | 1 | 1 | #include<stdio.h> | |
#include<stdlib.h> | 2 | 2 | #include<stdlib.h> | |
3 | #include<string.h> | |||
char* generate_string(int length) | 3 | 4 | char* generate_string(int length) | |
{ | 4 | 5 | { | |
//Random number seed | 5 | 6 | //Random number seed | |
srand((unsigned int) ctime(0)); | 6 | 7 | srand((unsigned int) ctime(0)); | |
char * buff; | 7 | 8 | char * buff; | |
buff=(char *)malloc(sizeof(char)*length); | 8 | 9 | buff=(char *)malloc(sizeof(char)*length); | |
int i; | 9 | 10 | int i; | |
for(i=0;i< length-1;i++){ | 10 | 11 | for(i=0;i< length-1;i++){ | |
buff[i] = rand() % rand() % (126 - 33 + 1) + 33; | 11 | 12 | buff[i] = rand() % rand() % (126 - 33 + 1) + 33; | |
} | 12 | 13 | } | |
buff[i] = '\0'; | 13 | 14 | buff[i] = '\0'; | |
return buff; | 14 | 15 | return buff; | |
} | 15 | 16 | } | |
int main() | 16 | 17 | int main() | |
{ | 17 | 18 | { | |
char *buf; | 18 | 19 | char *buf; | |
buf = generate_string(5); | 19 | 20 | buf = generate_string(5); | |
printf("String of 5: %s", buf); | 20 | 21 | printf("String of 5: %s, size: %lu\n", buf, strlen(buf)); | |
free(buf); | 21 | 22 | free(buf); | |
22 | 23 | |||
buf = generate_string(40); | 23 | 24 | buf = generate_string(40); | |
printf("String of 5: %s", buf); | 24 | 25 | printf("String of 40: %s, size: %lu\n", buf, strlen(buf)); | |
free(buf); | 25 | 26 | free(buf); | |
26 | 27 | |||
buf = generate_string(80); | 27 | 28 | buf = generate_string(80); | |
printf("String of 5: %s", buf); | 28 | 29 | printf("String of 80: %s,, size: %lu\n", buf, strlen(buf)); | |
free(buf); | 29 | 30 | free(buf); | |
30 | 31 | |||
return 0; | 31 | 32 | return 0; | |
} | 32 | 33 | } |
network/rtt_client.c
View file @
c12e3e1
#include "../rasperf.h" | 1 | 1 | #include "../rasperf.h" | |
#include<stdio.h> | 2 | 2 | #include<stdio.h> | |
#include<stdlib.h> | 3 | 3 | #include<stdlib.h> | |
#include<arpa/inet.h> | 4 | 4 | #include<arpa/inet.h> | |
#include<sys/types.h> | 5 | 5 | #include<sys/types.h> | |
#include<sys/socket.h> | 6 | 6 | #include<sys/socket.h> | |
#include<netdb.h> | 7 | 7 | #include<netdb.h> | |
#include<string.h> | 8 | 8 | #include<string.h> | |
//Macro definitions | 9 | 9 | //Macro definitions | |
#define handle_error(msg) \ | 10 | 10 | #define handle_error(msg) \ | |
do { perror(msg); exit(1);} while(0); | 11 | 11 | do { perror(msg); exit(1);} while(0); | |
#define BUFFER_SIZE 2048 | 12 | 12 | #define BUFFER_SIZE 2048 | |
#define STRIDE_SIZE 64 | 13 | 13 | #define STRIDE_SIZE 64 | |
#define BACKLOG 32 //buff size/stride size | 14 | 14 | #define BACKLOG 32 //buff size/stride size | |
15 | 15 | |||
//A random string generator of given length | 16 | 16 | //A random string generator of given length | |
char* generate_string(int length) | 17 | 17 | char* generate_string(int length) | |
{ | 18 | 18 | { | |
//Random number seed | 19 | 19 | //Random number seed | |
srand((unsigned int) ctime(0)); | 20 | 20 | srand((unsigned int) ctime(0)); | |
char * buff; | 21 | 21 | char * buff; | |
buff=(char *)malloc(sizeof(char)*length); | 22 | 22 | buff=(char *)malloc(sizeof(char)*(length+1)); | |
int i; | 23 | 23 | int i; | |
for(i=0;i< length-1;i++){ | 24 | 24 | for(i=0;i< length;i++){ | |
buff[i] = rand() % rand() % (126 - 33 + 1) + 33; | 25 | 25 | buff[i] = rand() % rand() % (126 - 33 + 1) + 33; | |
} | 26 | 26 | } | |
buff[i] = '\0'; | 27 | 27 | buff[i] = '\0'; | |
return buff; | 28 | 28 | return buff; | |
} | 29 | 29 | } | |
30 | 30 | |||
int main(int argc, char*argv[]) | 31 | 31 | int main(int argc, char*argv[]) | |
{ | 32 | 32 | { | |
int socket_fd, rc; | 33 | 33 | int socket_fd, rc; | |
char buf[BUFFER_SIZE]; | 34 | 34 | char buff[BUFFER_SIZE]; | |
char *msg; | 35 | 35 | char *msg; | |
float start_delta = 0, close_delta = 0; | 36 | 36 | float delta = 0; | |
if(argc<2){ | 37 | 37 | if(argc<2){ | |
handle_error("<usage>:tcp_client <IP address>"); | 38 | 38 | handle_error("<usage>:tcp_client <IP address>"); | |
} | 39 | 39 | } | |
//Retrieve the protocol number mapping | 40 | 40 | //Retrieve the protocol number mapping | |
//from /etc/protocols file | 41 | 41 | //from /etc/protocols file | |
struct protoent *proto_entry; | 42 | 42 | struct protoent *proto_entry; | |
proto_entry = getprotobyname("tcp"); | 43 | 43 | proto_entry = getprotobyname("tcp"); | |
44 | 44 | |||
45 | 45 | |||
//My address information to bind to | 46 | 46 | //My address information to bind to | |
struct sockaddr_in server; | 47 | 47 | struct sockaddr_in server; | |
memset(&server, 0, sizeof(struct sockaddr)); | 48 | 48 | memset(&server, 0, sizeof(struct sockaddr)); | |
server.sin_family = AF_INET; | 49 | 49 | server.sin_family = AF_INET; | |
server.sin_port = htons(8000); | 50 | 50 | server.sin_port = htons(8000); | |
51 | 51 | |||
rc= inet_pton(AF_INET, argv[1], &server.sin_addr); | 52 | 52 | rc= inet_pton(AF_INET, argv[1], &server.sin_addr); | |
if(rc == -1){ | 53 | 53 | if(rc == -1){ | |
handle_error("Address Error"); | 54 | 54 | handle_error("Address Error"); | |
} | 55 | 55 | } | |
time starttime, endtime; | 56 | 56 | time starttime, endtime; | |
//accept incoming connections | 57 | 57 | //accept incoming connections | |
int addr_size = sizeof(struct sockaddr); | 58 | 58 | int addr_size = sizeof(struct sockaddr); | |
int i; | 59 | 59 | int i; | |
int protonum = proto_entry->p_proto; | 60 | 60 | int protonum = proto_entry->p_proto; | |
61 | 61 | |||
//Open an socket end-point for this TCP Server | 62 | 62 | //Open an socket end-point for this TCP Server | |
if((socket_fd = socket(AF_INET, SOCK_STREAM, protonum))<0){ | 63 | 63 | if((socket_fd = socket(AF_INET, SOCK_STREAM, protonum))<0){ | |
handle_error("Socket Error"); | 64 | 64 | handle_error("Socket Error"); | |
} | 65 | 65 | } | |
if(connect(socket_fd, (struct sockaddr*)&server, sizeof(server))<0){ | 66 | 66 | if(connect(socket_fd, (struct sockaddr*)&server, sizeof(server))<0){ | |
handle_error("Connection Error"); | 67 | 67 | handle_error("Connection Error"); | |
} | 68 | 68 | } | |
69 | 69 | |||
for(i=1;i<=BACKLOG;i++){ | 70 | 70 | for(i=1;i<=BACKLOG;i++){ | |
//increase the sent message in strides of 64 | 71 | 71 | //increase the sent message in strides of 64 | |
//look for for peak rtt | 72 | 72 | //look for for peak rtt | |
msg = generate_string(STRIDE_SIZE * i); | 73 | 73 | msg = generate_string(STRIDE_SIZE * i); | |
printf("String Generated: \"%s\"",msg); | 74 | 74 | //printf("String Generated: \"%s\" size:%lu\n",msg, strlen(msg)); | |
getTime(starttime); | 75 | 75 | getTime(starttime); | |
if(send(socket_fd, msg, sizeof(msg), 0) <0){ | 76 | 76 | if(send(socket_fd, msg, strlen(msg), 0) <0){ | |
handler_error("Send Error"); | 77 | 77 | handle_error("Send Error"); | |
} | 78 | 78 | } | |
//The recv buffer size is same as the one we sent | 79 | 79 | //The recv buffer size is same as the one we sent | |
if(recv(socket_fd, buff, sizeof(msg), 0) != sizeof(msg)){ | 80 | 80 | if(recv(socket_fd, buff, strlen(msg), 0) != strlen(msg)){ | |
handle_error("Data over/ Receive Error"); | 81 | 81 | handle_error("Data over/ Receive Error"); | |
} | 82 | 82 | } | |
getTime(endtime); | 83 | 83 | getTime(endtime); | |
delta+=diff(endtime, starttime); | 84 | 84 | delta+=(diff(endtime, starttime)); | |
printf("Single RTT %f", diff(endtime, starttime)); | 85 | 85 | printf("Single RTT %f\n", diff(endtime, starttime)); | |
86 | 86 | |||
} | 87 | 87 | } | |
88 | 88 | |||
close(socket_fd); | 89 | 89 | close(socket_fd); | |
printf("Averaged RTT =%f us\n", delta/BACKLOG); | 90 | 90 | printf("Averaged RTT =%f us\n", delta/BACKLOG); | |
return 0; | 91 | 91 | return 0; | |
} | 92 | 92 | } | |
93 | 93 |
network/rtt_server.c
View file @
c12e3e1
#include "../rasperf.h" | 1 | 1 | #include "../rasperf.h" | |
#include<stdio.h> | 2 | 2 | #include<stdio.h> | |
#include<stdlib.h> | 3 | 3 | #include<stdlib.h> | |
#include<arpa/inet.h> | 4 | 4 | #include<arpa/inet.h> | |
#include<sys/types.h> | 5 | 5 | #include<sys/types.h> | |
#include<sys/wait.h> | 6 | 6 | #include<sys/wait.h> | |
#include<sys/socket.h> | 7 | 7 | #include<sys/socket.h> | |
#include<netdb.h> | 8 | 8 | #include<netdb.h> | |
#include<string.h> | 9 | 9 | #include<string.h> | |
10 | 10 | |||
//Macro definitions | 11 | 11 | //Macro definitions | |
#define handle_error(msg) \ | 12 | 12 | #define handle_error(msg) \ | |
do { perror(msg); exit(1);} while(0); | 13 | 13 | do { perror(msg); exit(1);} while(0); | |
#define LISTEN_BACKLOG 100 | 14 | 14 | #define LISTEN_BACKLOG 100 | |
#define BUFFER_SIZE 2048 | 15 | 15 | #define BUFFER_SIZE 2048 | |
16 | #define STRIDE_SIZE 64 | |||
17 | #define BACKLOG 32 | |||
16 | 18 | |||
int main(int argc, char*argv[]) | 17 | 19 | int main(int argc, char*argv[]) | |
{ | 18 | 20 | { | |
int socket_fd, rc; | 19 | 21 | int socket_fd, rc; | |
char buff[BUFFER_SIZE], msg[BUFFER_SIZE]; | 20 | 22 | char buff[BUFFER_SIZE]; | |
char | 21 | |||
float setup_delta, close_delta; | 22 | 23 | float setup_delta, close_delta; | |
if(argc<1){ | 23 | 24 | if(argc<1){ | |
handle_error("<usage>:tcp_server"); | 24 | 25 | handle_error("<usage>:tcp_server"); | |
} | 25 | 26 | } | |
//Retrieve the protocol number mapping | 26 | 27 | //Retrieve the protocol number mapping | |
//from /etc/protocols file | 27 | 28 | //from /etc/protocols file | |
struct protoent *proto_entry; | 28 | 29 | struct protoent *proto_entry; | |
proto_entry = getprotobyname("tcp"); | 29 | 30 | proto_entry = getprotobyname("tcp"); | |
30 | 31 | |||
//Open an socket end-point for this TCP Server | 31 | 32 | //Open an socket end-point for this TCP Server | |
socket_fd = socket(AF_INET, SOCK_STREAM, proto_entry->p_proto); | 32 | 33 | socket_fd = socket(AF_INET, SOCK_STREAM, proto_entry->p_proto); | |
if(socket_fd == -1){ | 33 | 34 | if(socket_fd == -1){ | |
handle_error("Socket descriptor creation failed"); | 34 | 35 | handle_error("Socket descriptor creation failed"); | |
} | 35 | 36 | } | |
36 | 37 | |||
//My address information to bind to | 37 | 38 | //My address information to bind to | |
struct sockaddr_in sock_addr; | 38 | 39 | struct sockaddr_in sock_addr; | |
memset(&sock_addr, 0, sizeof(struct sockaddr)); | 39 | 40 | memset(&sock_addr, 0, sizeof(struct sockaddr)); | |
sock_addr.sin_family = AF_INET; | 40 | 41 | sock_addr.sin_family = AF_INET; | |
sock_addr.sin_addr.s_addr = htonl(INADDR_ANY); | 41 | 42 | sock_addr.sin_addr.s_addr = htonl(INADDR_ANY); | |
sock_addr.sin_port = htons(8000); | 42 | 43 | sock_addr.sin_port = htons(8000); | |
43 | 44 | |||
44 | 45 | |||
rc = bind(socket_fd, (struct sockaddr*)&sock_addr, sizeof(sock_addr)); | 45 | 46 | rc = bind(socket_fd, (struct sockaddr*)&sock_addr, sizeof(sock_addr)); | |
if(rc == -1){ | 46 | 47 | if(rc == -1){ | |
handle_error("Bind failure"); | 47 | 48 | handle_error("Bind failure"); | |
} | 48 | 49 | } | |
rc = listen(socket_fd, LISTEN_BACKLOG); | 49 | 50 | rc = listen(socket_fd, LISTEN_BACKLOG); | |
if(rc == -1){ | 50 | 51 | if(rc == -1){ | |
handle_error(" Listen Error"); | 51 | 52 | handle_error(" Listen Error"); | |
} | 52 | 53 | } | |
53 | 54 | |||
time starttime, endtime; | 54 | 55 | time starttime, endtime; | |
//accept incoming connections | 55 | 56 | //accept incoming connections | |
int connfd, i, pid, addr_size = sizeof(struct sockaddr); | 56 | 57 | int connfd, i, pid, addr_size = sizeof(struct sockaddr); | |
printf("Accept Connection\n"); | 57 | 58 | printf("Accept Connection\n"); | |
connfd = accept(socket_fd, (struct sockaddr *)NULL, NULL); | 58 | 59 | connfd = accept(socket_fd, (struct sockaddr *)NULL, NULL); | |
if( connfd == -1){ | 59 | 60 | if( connfd == -1){ | |
handle_error("Accept failed"); | 60 | 61 | handle_error("Accept failed"); | |
} | 61 | 62 | } | |
for(i=1;i<=BACKLOG;i++) | 62 | 63 | for(i=1;i<=BACKLOG;i++) | |
{ | 63 | 64 | { | |
65 | printf("%d\n",i); | |||
getTime(starttime); | 64 | 66 | getTime(starttime); | |
if(recv(connfd, buff, sizeof(i* STRIDE_SIZE), 0)!= sizeof(i* STRIDE_SIZE)){ | 65 | 67 | if(recv(connfd, buff,i* STRIDE_SIZE, 0) != i* STRIDE_SIZE){ | |
68 | printf("String :%s, strlen:%d, stride:%d\n", buff, strlen(buff), i*STRIDE_SIZE); | |||
handle_error("Receive Error/ Data Done"); | 66 | 69 | handle_error("Receive Error/ Data Done"); | |
} | 67 | 70 | } | |
if(send(connfd, buff, sizeof(i * STRIDE_SIZE), 0)<0){ | 68 | 71 | if(send(connfd, buff,i * STRIDE_SIZE, 0)<0){ | |
handle_error("Send Error"); | 69 | 72 | handle_error("Send Error"); | |
} | 70 | 73 | } | |
getTime(endtime); | 71 | 74 | getTime(endtime); | |
} | 72 | 75 | } | |
73 | 76 |