Compare View

switch
from
...
to
 
Commits (2)

Diff

Showing 15 changed files Inline Diff

network/overhead_client.c View file @ e5cf2c6
#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++){
//Open an socket end-point for this TCP Server 42
if((socket_fd = socket(AF_INET, SOCK_STREAM, protonum))<0){ 43 42 //Open an socket end-point for this TCP Server
handle_error("Socket Error"); 44 43 if((socket_fd = socket(AF_INET, SOCK_STREAM, protonum))<0){
} 45 44 handle_error("Socket Error");
getTime(starttime); 46 45 }
46 getTime(starttime);
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);
int z; /* Status code */ 57 57 int z; /* Status code */
int s; /* Socket s */ 58 58 int s; /* Socket s */
struct linger so_linger; 59 59 struct linger so_linger;
60 60
so_linger.l_onoff = 1; 61 61 so_linger.l_onoff = 1;
so_linger.l_linger = 0; 62 62 so_linger.l_linger = 0;
z = setsockopt(socket_fd, 63 63 z = setsockopt(socket_fd,
SOL_SOCKET, 64 64 SOL_SOCKET,
SO_LINGER, 65 65 SO_LINGER,
&so_linger, 66 66 &so_linger,
sizeof so_linger); 67 67 sizeof so_linger);
68 68
if ( z ) 69 69 if ( z )
perror("setsockopt(2)"); 70 70 perror("setsockopt(2)");
71 71
getTime(starttime); 72 72 getTime(starttime);
close(socket_fd); 73 73 close(socket_fd);
getTime(endtime); 74
75 74 getTime(endtime);
//Calculate connection overhead server side 76 75
close_delta+=diff(endtime,starttime); 77 76 //Calculate connection overhead server side
network/peak_client.c View file @ e5cf2c6
#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 1 * MB 12 12 #define BUFFER_SIZE 1 * MB
13 #define MB 1024 * 1024
14 #define STRIDE_SIZE 64
15 #define BACKLOG 64 //buff size/stride size
16
17 //A random string generator of given length
18 char* generate_string(int length)
19 {
20 //Random number seed
21 srand((unsigned int) ctime(0));
22 char * buff;
23 buff=(char *)malloc(sizeof(char)*(length+1));
24 int i;
25 for(i=0;i< length;i++){
26 buff[i] = rand() % rand() % (126 - 33 + 1) + 33;
27 }
28 buff[i] = '\0';
29 return buff;
30 }
31
#define MB 1024 * 1024 13 32 int main(int argc, char*argv[])
#define STRIDE_SIZE 64 14 33 {
#define BACKLOG 64 //buff size/stride size 15 34 int socket_fd, rc;
16 35 char buff[BUFFER_SIZE];
36 char *msg;
37 float delta = 0, min =9999;
//A random string generator of given length 17 38 if(argc<2){
char* generate_string(int length) 18 39 handle_error("<usage>:tcp_client <IP address>");
{ 19 40 }
//Random number seed 20 41 //Retrieve the protocol number mapping
srand((unsigned int) ctime(0)); 21 42 //from /etc/protocols file
char * buff; 22 43 struct protoent *proto_entry;
buff=(char *)malloc(sizeof(char)*(length+1)); 23 44 proto_entry = getprotobyname("tcp");
int i; 24 45
for(i=0;i< length;i++){ 25 46
buff[i] = rand() % rand() % (126 - 33 + 1) + 33; 26 47 //My address information to bind to
} 27 48 struct sockaddr_in server;
buff[i] = '\0'; 28 49 memset(&server, 0, sizeof(struct sockaddr));
return buff; 29 50 server.sin_family = AF_INET;
} 30 51 server.sin_port = htons(9);
31 52
int main(int argc, char*argv[]) 32 53 rc= inet_pton(AF_INET, argv[1], &server.sin_addr);
{ 33 54 if(rc == -1){
int socket_fd, rc; 34 55 handle_error("Address Error");
char buff[BUFFER_SIZE]; 35 56 }
char *msg; 36 57 time starttime, endtime;
float delta = 0, min =9999; 37 58 //accept incoming connections
if(argc<2){ 38 59 int addr_size = sizeof(struct sockaddr);
handle_error("<usage>:tcp_client <IP address>"); 39 60 int i;
} 40 61 int protonum = proto_entry->p_proto;
62
63 //Open an socket end-point for this TCP Server
64 if((socket_fd = socket(AF_INET, SOCK_STREAM, protonum))<0){
65 handle_error("Socket Error");
66 }
67 if(connect(socket_fd, (struct sockaddr*)&server, sizeof(server))<0){
68 handle_error("Connection Error");
69 }
70 msg = generate_string(BUFFER_SIZE);
//Retrieve the protocol number mapping 41 71 for(i=1;i<=BACKLOG;i++){
//from /etc/protocols file 42 72 getTime(starttime);
struct protoent *proto_entry; 43 73 if(send(socket_fd, msg, strlen(msg), 0) <0){
proto_entry = getprotobyname("tcp"); 44 74 handle_error("Send Error");
45
46
//My address information to bind to 47
struct sockaddr_in server; 48
memset(&server, 0, sizeof(struct sockaddr)); 49 75 }
server.sin_family = AF_INET; 50
server.sin_port = htons(9); 51
52
rc= inet_pton(AF_INET, argv[1], &server.sin_addr); 53
if(rc == -1){ 54
handle_error("Address Error"); 55
} 56
time starttime, endtime; 57
//accept incoming connections 58
int addr_size = sizeof(struct sockaddr); 59
int i; 60 76 getTime(endtime);
int protonum = proto_entry->p_proto; 61 77 delta+=(diff(endtime, starttime));
62 78 if(delta < min) min = delta;
//Open an socket end-point for this TCP Server 63 79 printf("Single Tput %fBps\n",(BUFFER_SIZE/ diff(endtime, starttime)));
if((socket_fd = socket(AF_INET, SOCK_STREAM, protonum))<0){ 64 80 }
handle_error("Socket Error"); 65 81
} 66 82 close(socket_fd);
83 printf("GoodPut = %f Bps, MaxTput= %f Bps", (BUFFER_SIZE)*(BACKLOG/delta), (BUFFER_SIZE/min));
if(connect(socket_fd, (struct sockaddr*)&server, sizeof(server))<0){ 67 84 return 0;
handle_error("Connection Error"); 68 85 }
} 69 86
msg = generate_string(BUFFER_SIZE); 70 87
for(i=1;i<=BACKLOG;i++){ 71 88
getTime(starttime); 72
if(send(socket_fd, msg, strlen(msg), 0) <0){ 73
handle_error("Send Error"); 74
} 75
getTime(endtime); 76
delta+=(diff(endtime, starttime)); 77
if(delta < min) min = delta; 78
printf("Single Tput %fBps\n",(BUFFER_SIZE/ diff(endtime, starttime))); 79
} 80
81
close(socket_fd); 82
printf("GoodPut = %f Bps, MaxTput= %f Bps", (BUFFER_SIZE)*(BACKLOG/delta), (BUFFER_SIZE/min)); 83
return 0; 84
} 85
86
87
88
network/rtt_client.c View file @ e5cf2c6
#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 1024 * 1024 12 12 #define BUFFER_SIZE 1024 * 1024
#define STRIDE_SIZE 512 13 13 #define STRIDE_SIZE 512
#define BACKLOG 5 //buff size/stride size 14 14 #define BACKLOG 5 //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+1)); 22 22 buff=(char *)malloc(sizeof(char)*(length+1));
int i; 23 23 int i;
for(i=0;i< length;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 buff[BUFFER_SIZE]; 34 34 char buff[BUFFER_SIZE];
char *msg; 35 35 char *msg;
float 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(7); 50 50 server.sin_port = htons(7);
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\" size:%lu\n",msg, strlen(msg)); 74 74 //printf("String Generated: \"%s\" size:%lu\n",msg, strlen(msg));
getTime(starttime); 75 75 getTime(starttime);
if(send(socket_fd, msg, strlen(msg), 0) <0){ 76 76 if(send(socket_fd, msg, strlen(msg), 0) <0){
handle_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, strlen(msg), 0) != strlen(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\n", diff(endtime, starttime)); 85 85 printf("Single RTT %f\n", diff(endtime, starttime));
86 86
} 87 87 }
network/standby_servers/peak_server.c View file @ e5cf2c6
File was created 1 #include "../rasperf.h"
2 #include<stdio.h>
3 #include<stdlib.h>
4 #include<arpa/inet.h>
5 #include<sys/types.h>
6 #include<sys/wait.h>
7 #include<sys/socket.h>
8 #include<netdb.h>
9 #include<string.h>
10
11 //Macro definitions
12 #define handle_error(msg) \
13 do { perror(msg); exit(1);} while(0);
14 #define LISTEN_BACKLOG 100
15 #define BUFFER_SIZE 5 * MB
16 #define MB 1024*1024
17 #define STRIDE_SIZE 64
18 #define BACKLOG 64
19
20 int main(int argc, char*argv[])
21 {
22 int socket_fd, rc;
23 char buff[BUFFER_SIZE];
24 float setup_delta, close_delta;
25 if(argc<1){
26 handle_error("<usage>:tcp_server");
27 }
28 //Retrieve the protocol number mapping
29 //from /etc/protocols file
30 struct protoent *proto_entry;
31 proto_entry = getprotobyname("tcp");
32
33 //Open an socket end-point for this TCP Server
34 socket_fd = socket(AF_INET, SOCK_STREAM, proto_entry->p_proto);
35 if(socket_fd == -1){
36 handle_error("Socket descriptor creation failed");
37 }
38
39 //My address information to bind to
40 struct sockaddr_in sock_addr;
41 memset(&sock_addr, 0, sizeof(struct sockaddr));
42 sock_addr.sin_family = AF_INET;
43 sock_addr.sin_addr.s_addr = htonl(INADDR_ANY);
44 sock_addr.sin_port = htons(8000);
45
46
47 rc = bind(socket_fd, (struct sockaddr*)&sock_addr, sizeof(sock_addr));
48 if(rc == -1){
49 handle_error("Bind failure");
50 }
51 rc = listen(socket_fd, LISTEN_BACKLOG);
52 if(rc == -1){
53 handle_error(" Listen Error");
54 }
55
56 time starttime, endtime;
57 //accept incoming connections
58 int connfd, i, pid, addr_size = sizeof(struct sockaddr);
59 printf("Accept Connection\n");
60 connfd = accept(socket_fd, (struct sockaddr *)NULL, NULL);
61 if( connfd == -1){
62 handle_error("Accept failed");
63 }
64
65 getTime(starttime);
66 for(i=1;i<=BACKLOG;i++)
67 {
68 if(recv(connfd, buff,BUFFER_SIZE, 0) == -1){
69 handle_error("Receive Error/ Data Done");
70 }
71 }
72 getTime(endtime);
73
74 close(socket_fd);
75 close(connfd);
76 printf("Data Receided:%d MB, Time:%f s \n",i*BUFFER_SIZE, diff(endtime, starttime));
77 return 0;
78 }
79
80
#include "../rasperf.h" 1 81
#include<stdio.h> 2
#include<stdlib.h> 3
#include<arpa/inet.h> 4
#include<sys/types.h> 5
#include<sys/wait.h> 6
#include<sys/socket.h> 7
#include<netdb.h> 8
#include<string.h> 9
10
//Macro definitions 11
#define handle_error(msg) \ 12
do { perror(msg); exit(1);} while(0); 13
#define LISTEN_BACKLOG 100 14
#define BUFFER_SIZE 5 * MB 15
#define MB 1024*1024 16
#define STRIDE_SIZE 64 17
#define BACKLOG 64 18
19
int main(int argc, char*argv[]) 20
{ 21
int socket_fd, rc; 22
char buff[BUFFER_SIZE]; 23
float setup_delta, close_delta; 24
if(argc<1){ 25
handle_error("<usage>:tcp_server"); 26
} 27
//Retrieve the protocol number mapping 28
//from /etc/protocols file 29
struct protoent *proto_entry; 30
proto_entry = getprotobyname("tcp"); 31
32
//Open an socket end-point for this TCP Server 33
socket_fd = socket(AF_INET, SOCK_STREAM, proto_entry->p_proto); 34
if(socket_fd == -1){ 35
handle_error("Socket descriptor creation failed"); 36
} 37
38
//My address information to bind to 39
struct sockaddr_in sock_addr; 40
memset(&sock_addr, 0, sizeof(struct sockaddr)); 41
sock_addr.sin_family = AF_INET; 42
sock_addr.sin_addr.s_addr = htonl(INADDR_ANY); 43
sock_addr.sin_port = htons(8000); 44
45
46
rc = bind(socket_fd, (struct sockaddr*)&sock_addr, sizeof(sock_addr)); 47
if(rc == -1){ 48
handle_error("Bind failure"); 49
} 50
rc = listen(socket_fd, LISTEN_BACKLOG); 51
if(rc == -1){ 52
handle_error(" Listen Error"); 53
} 54
55
time starttime, endtime; 56
//accept incoming connections 57
int connfd, i, pid, addr_size = sizeof(struct sockaddr); 58
printf("Accept Connection\n"); 59
connfd = accept(socket_fd, (struct sockaddr *)NULL, NULL); 60
if( connfd == -1){ 61
handle_error("Accept failed"); 62
} 63
64
getTime(starttime); 65
for(i=1;i<=BACKLOG;i++) 66
{ 67
if(recv(connfd, buff,BUFFER_SIZE, 0) == -1){ 68
handle_error("Receive Error/ Data Done"); 69
network/standby_servers/random_str.c View file @ e5cf2c6
File was created 1 #include<stdio.h>
2 #include<stdlib.h>
3 #include<string.h>
4 char* generate_string(int length)
5 {
6 //Random number seed
7 srand((unsigned int) ctime(0));
8 char * buff;
9 buff=(char *)malloc(sizeof(char)*length);
10 int i;
11 for(i=0;i< length-1;i++){
12 buff[i] = rand() % rand() % (126 - 33 + 1) + 33;
13 }
14 buff[i] = '\0';
15 return buff;
16 }
17 int main()
18 {
19 char *buf;
20 buf = generate_string(5);
21 printf("String of 5: %s, size: %lu\n", buf, strlen(buf));
22 free(buf);
23
24 buf = generate_string(40);
25 printf("String of 40: %s, size: %lu\n", buf, strlen(buf));
26 free(buf);
27
28 buf = generate_string(80);
29 printf("String of 80: %s,, size: %lu\n", buf, strlen(buf));
30 free(buf);
31
32 return 0;
33 }
#include<stdio.h> 1 34
#include<stdlib.h> 2
#include<string.h> 3
char* generate_string(int length) 4
{ 5
//Random number seed 6
srand((unsigned int) ctime(0)); 7
char * buff; 8
buff=(char *)malloc(sizeof(char)*length); 9
int i; 10
for(i=0;i< length-1;i++){ 11
buff[i] = rand() % rand() % (126 - 33 + 1) + 33; 12
} 13
buff[i] = '\0'; 14
return buff; 15
} 16
int main() 17
{ 18
char *buf; 19
buf = generate_string(5); 20
printf("String of 5: %s, size: %lu\n", buf, strlen(buf)); 21
free(buf); 22
23
buf = generate_string(40); 24
printf("String of 40: %s, size: %lu\n", buf, strlen(buf)); 25
free(buf); 26
27
buf = generate_string(80); 28
printf("String of 80: %s,, size: %lu\n", buf, strlen(buf)); 29
free(buf); 30
network/standby_servers/rtt_server.c View file @ e5cf2c6
File was created 1 #include "../rasperf.h"
2 #include<stdio.h>
3 #include<stdlib.h>
4 #include<arpa/inet.h>
5 #include<sys/types.h>
6 #include<sys/wait.h>
7 #include<sys/socket.h>
8 #include<netdb.h>
9 #include<string.h>
10
11 //Macro definitions
12 #define handle_error(msg) \
13 do { perror(msg); exit(1);} while(0);
14 #define LISTEN_BACKLOG 100
15 #define BUFFER_SIZE 1024 * 1024
16 #define STRIDE_SIZE 64
17 #define BACKLOG 128
18
19 int main(int argc, char*argv[])
20 {
21 int socket_fd, rc;
22 char buff[BUFFER_SIZE];
23 float setup_delta, close_delta;
24 if(argc<1){
25 handle_error("<usage>:tcp_server");
26 }
27 //Retrieve the protocol number mapping
28 //from /etc/protocols file
29 struct protoent *proto_entry;
30 proto_entry = getprotobyname("tcp");
31
32 //Open an socket end-point for this TCP Server
33 socket_fd = socket(AF_INET, SOCK_STREAM, proto_entry->p_proto);
34 if(socket_fd == -1){
35 handle_error("Socket descriptor creation failed");
36 }
37
38 //My address information to bind to
39 struct sockaddr_in sock_addr;
40 memset(&sock_addr, 0, sizeof(struct sockaddr));
41 sock_addr.sin_family = AF_INET;
42 sock_addr.sin_addr.s_addr = htonl(INADDR_ANY);
43 sock_addr.sin_port = htons(8000);
44
45
46 rc = bind(socket_fd, (struct sockaddr*)&sock_addr, sizeof(sock_addr));
47 if(rc == -1){
48 handle_error("Bind failure");
49 }
50 rc = listen(socket_fd, LISTEN_BACKLOG);
51 if(rc == -1){
52 handle_error(" Listen Error");
53 }
54
55 time starttime, endtime;
56 //accept incoming connections
57 int connfd, i, pid, addr_size = sizeof(struct sockaddr);
58 printf("Accept Connection\n");
59 connfd = accept(socket_fd, (struct sockaddr *)NULL, NULL);
60 if( connfd == -1){
61 handle_error("Accept failed");
62 }
63 for(i=1;i<=BACKLOG;i++)
64 {
65 printf("%d\n",i);
66 getTime(starttime);
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);
69 handle_error("Receive Error/ Data Done");
70 }
71 if(send(connfd, buff,i * STRIDE_SIZE, 0)<0){
72 handle_error("Send Error");
73 }
74 getTime(endtime);
75 }
76
77 close(socket_fd);
78 close(connfd);
79 printf("Connection %d closed in Child\n",i);
80 return 0;
81 }
82
83
#include "../rasperf.h" 1 84
#include<stdio.h> 2
#include<stdlib.h> 3
#include<arpa/inet.h> 4
#include<sys/types.h> 5
#include<sys/wait.h> 6
#include<sys/socket.h> 7
#include<netdb.h> 8
#include<string.h> 9
10
//Macro definitions 11
#define handle_error(msg) \ 12
do { perror(msg); exit(1);} while(0); 13
#define LISTEN_BACKLOG 100 14
#define BUFFER_SIZE 1024 * 1024 15
#define STRIDE_SIZE 64 16
#define BACKLOG 128 17
18
int main(int argc, char*argv[]) 19
{ 20
int socket_fd, rc; 21
char buff[BUFFER_SIZE]; 22
float setup_delta, close_delta; 23
if(argc<1){ 24
handle_error("<usage>:tcp_server"); 25
} 26
//Retrieve the protocol number mapping 27
//from /etc/protocols file 28
struct protoent *proto_entry; 29
proto_entry = getprotobyname("tcp"); 30
31
//Open an socket end-point for this TCP Server 32
socket_fd = socket(AF_INET, SOCK_STREAM, proto_entry->p_proto); 33
if(socket_fd == -1){ 34
handle_error("Socket descriptor creation failed"); 35
} 36
37
//My address information to bind to 38
struct sockaddr_in sock_addr; 39
memset(&sock_addr, 0, sizeof(struct sockaddr)); 40
sock_addr.sin_family = AF_INET; 41
sock_addr.sin_addr.s_addr = htonl(INADDR_ANY); 42
sock_addr.sin_port = htons(8000); 43
44
45
rc = bind(socket_fd, (struct sockaddr*)&sock_addr, sizeof(sock_addr)); 46
if(rc == -1){ 47
handle_error("Bind failure"); 48
} 49
rc = listen(socket_fd, LISTEN_BACKLOG); 50
if(rc == -1){ 51
handle_error(" Listen Error"); 52
} 53
54
time starttime, endtime; 55
//accept incoming connections 56
int connfd, i, pid, addr_size = sizeof(struct sockaddr); 57
printf("Accept Connection\n"); 58
connfd = accept(socket_fd, (struct sockaddr *)NULL, NULL); 59
if( connfd == -1){ 60
handle_error("Accept failed"); 61
} 62
for(i=1;i<=BACKLOG;i++) 63
{ 64
printf("%d\n",i); 65
getTime(starttime); 66
if(recv(connfd, buff,i* STRIDE_SIZE, 0) != i* STRIDE_SIZE){ 67
printf("String :%s, strlen:%d, stride:%d\n", buff, strlen(buff), i*STRIDE_SIZE); 68
handle_error("Receive Error/ Data Done"); 69
} 70
if(send(connfd, buff,i * STRIDE_SIZE, 0)<0){ 71
handle_error("Send Error"); 72
} 73
network/standby_servers/tcp_rtt_client.bul View file @ e5cf2c6
File was created 1 #include "../rasperf.h"
2 #include<stdio.h>
3 #include<stdlib.h>
4 #include<arpa/inet.h>
5 #include<sys/types.h>
6 #include<sys/socket.h>
7 #include<netdb.h>
8 #include<string.h>
9 //Macro definitions
10 #define handle_error(msg) \
11 do { perror(msg); exit(1);} while(0);
12 #define BACKLOG 1
13 int main(int argc, char*argv[])
14 {
15 int socket_fd, rc;
16 float start_delta = 0, close_delta = 0;
17 if(argc<2){
18 handle_error("<usage>:tcp_client <IP address>");
19 }
20 //Retrieve the protocol number mapping
21 //from /etc/protocols file
22 struct protoent *proto_entry;
23 proto_entry = getprotobyname("tcp");
24
25
26 //My address information to bind to
27 struct sockaddr_in server;
28 memset(&server, 0, sizeof(struct sockaddr));
29 server.sin_family = AF_INET;
30 server.sin_port = htons(8000);
31
32 rc= inet_pton(AF_INET, argv[1], &server.sin_addr);
33 if(rc == -1){
34 handle_error("Address Error");
35 }
36 time starttime, endtime;
37 //accept incoming connections
38 int addr_size = sizeof(struct sockaddr);
39 int i;
40 int protonum = proto_entry->p_proto;
41 for(i=1;i<=BACKLOG;i++){
42 getTime(starttime);
43 //Open an socket end-point for this TCP Server
44 if((socket_fd = socket(AF_INET, SOCK_STREAM, protonum))<0){
45 handle_error("Socket descriptor creation failed");
46 }
47 if((connect(socket_fd, (struct sockaddr*)&server, sizeof(server)))<0){
48 handle_error("Connect failed");
49 }
50 /*The end calculated here will miss time taken for ACK K+1
51 from the client. And so we have to one way delay
52 measured using another experiment*/
53 getTime(endtime);
54
55 //Calculate connection overhead client
56 start_delta+=diff(endtime,starttime);
57 printf("EndTime: %f usec\n", endtime.tv_sec + endtime.tv_usec*1e6);
58 printf("Start time:%f usec\n", starttime.tv_sec +starttime.tv_usec*1e6);
59 printf("Setup:%f\n",diff(endtime,starttime) + 25);
60
61 getTime(starttime);
62 sleep(1);
63 close(socket_fd);
64 getTime(endtime);
65 printf("Endtime %f usec\n", endtime.tv_sec + endtime.tv_usec*1e6);
66 printf("Start time:%f usec\n", starttime.tv_sec +starttime.tv_usec*1e6);
67 printf("TearDown:%f\n",diff(endtime,starttime) + 25);
68 //Calculate connection overhead server side
69 close_delta+=diff(endtime,starttime);
70 }
71 printf("Connection Setup =%f us\n", (start_delta + RTT/2 * BACKLOG)/BACKLOG);
72 printf("Connection Teardown =%f us\n", (close_delta + RTT/2 * BACKLOG)/BACKLOG);
73 return 0;
74 }
75
76
#include "../rasperf.h" 1 77
#include<stdio.h> 2
#include<stdlib.h> 3
#include<arpa/inet.h> 4
#include<sys/types.h> 5
#include<sys/socket.h> 6
#include<netdb.h> 7
#include<string.h> 8
//Macro definitions 9
#define handle_error(msg) \ 10
do { perror(msg); exit(1);} while(0); 11
#define BACKLOG 1 12
int main(int argc, char*argv[]) 13
{ 14
int socket_fd, rc; 15
float start_delta = 0, close_delta = 0; 16
if(argc<2){ 17
handle_error("<usage>:tcp_client <IP address>"); 18
} 19
//Retrieve the protocol number mapping 20
//from /etc/protocols file 21
struct protoent *proto_entry; 22
proto_entry = getprotobyname("tcp"); 23
24
25
//My address information to bind to 26
struct sockaddr_in server; 27
memset(&server, 0, sizeof(struct sockaddr)); 28
server.sin_family = AF_INET; 29
server.sin_port = htons(8000); 30
31
rc= inet_pton(AF_INET, argv[1], &server.sin_addr); 32
if(rc == -1){ 33
handle_error("Address Error"); 34
} 35
time starttime, endtime; 36
//accept incoming connections 37
int addr_size = sizeof(struct sockaddr); 38
int i; 39
int protonum = proto_entry->p_proto; 40
for(i=1;i<=BACKLOG;i++){ 41
getTime(starttime); 42
//Open an socket end-point for this TCP Server 43
if((socket_fd = socket(AF_INET, SOCK_STREAM, protonum))<0){ 44
handle_error("Socket descriptor creation failed"); 45
} 46
if((connect(socket_fd, (struct sockaddr*)&server, sizeof(server)))<0){ 47
handle_error("Connect failed"); 48
} 49
/*The end calculated here will miss time taken for ACK K+1 50
from the client. And so we have to one way delay 51
measured using another experiment*/ 52
getTime(endtime); 53
54
//Calculate connection overhead client 55
start_delta+=diff(endtime,starttime); 56
printf("EndTime: %f usec\n", endtime.tv_sec + endtime.tv_usec*1e6); 57
printf("Start time:%f usec\n", starttime.tv_sec +starttime.tv_usec*1e6); 58
printf("Setup:%f\n",diff(endtime,starttime) + 25); 59
60
getTime(starttime); 61
sleep(1); 62
close(socket_fd); 63
getTime(endtime); 64
printf("Endtime %f usec\n", endtime.tv_sec + endtime.tv_usec*1e6); 65
printf("Start time:%f usec\n", starttime.tv_sec +starttime.tv_usec*1e6); 66
printf("TearDown:%f\n",diff(endtime,starttime) + 25); 67
//Calculate connection overhead server side 68
close_delta+=diff(endtime,starttime); 69
1 1
#ifndef __RASPERF_H__ 2 2 #ifndef __RASPERF_H__
#define NULL '\0' 3 3 #define NULL '\0'
#define __RASPERF_H__ 4 4 #define __RASPERF_H__
#define RTT 35 //in MicroSec 5 5 #define RTT 35 //in MicroSec
#define PI 1 6 6 #define PI 1
#define x86 0 7 7 #define x86 0
#define CPU_CYCLES 900 8 8 #define CPU_CYCLES 900
#define MHz 1e6 9 9 #define MHz 1e6
#if defined(PI) && PI 10 10 #if defined(PI) && PI
#define time unsigned int 11 11 #define time unsigned int
#define getTime(var) \ 12 12 #define getTime(var) \
asm volatile (\ 13 13 asm volatile (\
"mrc p15, 0, %0, c9, c13, 0":\ 14 14 "mrc p15, 0, %0, c9, c13, 0":\
"=r" (var)); 15 15 "=r" (var));
#define readCCNTStatus(var) \ 16 16 #define readCCNTStatus(var) \
asm volatile (\ 17 17 asm volatile (\
"mrc p15, 0, %0, c9, c14, 0":\ 18 18 "mrc p15, 0, %0, c9, c14, 0":\
"=r" (var)); 19 19 "=r" (var));
#define diff(end, begin) \ 20 20 #define diff(end, begin) \
(end - begin) 21 21 (end - begin)
#endif 22 22 #endif
#if defined(x86) && x86 23 23 #if defined(x86) && x86
#define time struct timeval 24 24 #define time struct timeval
#define getTime(var) gettimeofday(&var, NULL) 25 25 #define getTime(var) gettimeofday(&var, NULL)
#define diff(end, begin) \ 26 26 #define diff(end, begin) \
((end.tv_sec*1e6+end.tv_usec) - (begin.tv_sec*1e6+ begin.tv_usec)) 27 27 ((end.tv_sec*1e6+end.tv_usec) - (begin.tv_sec*1e6+ begin.tv_usec))
#endif 28 28 #endif
#endif 29 29 #endif
30 30
31 31