diff --git a/offloading_binaries/Splice_recv/main.c b/offloading_binaries/Splice_recv/main.c deleted file mode 100644 index 873124f..0000000 --- a/offloading_binaries/Splice_recv/main.c +++ /dev/null @@ -1,177 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define _GNU_SOURCE /* See feature_test_macros(7) */ -#include -#include -#include - -#define ETH_P_IP 0x0800 /* Internet Protocol packet */ -#define ETH_ALEN 6 /* from */ -#define ETH_P_ALL 0x0003 - -#define MY_DEST_MAC0 0xba -#define MY_DEST_MAC1 0xf6 -#define MY_DEST_MAC2 0xb1 -#define MY_DEST_MAC3 0x71 -#define MY_DEST_MAC4 0x09 -#define MY_DEST_MAC5 0x64 - -#define DEFAULT_IF "wlan0" -#define BUF_SIZ 8192 - -int main(int argc, char *argv[]) -{ - int sockfd, listenfd; - socklen_t clilen; - struct ifreq if_idx; - struct ifreq if_mac; - int tx_len = 0; - char sendbuf[BUF_SIZ]; - struct ether_header *eh = (struct ether_header *) sendbuf; - struct iphdr *iph = (struct iphdr *) (sendbuf + sizeof(struct ether_header)); - struct sockaddr_ll socket_address; - char ifName[IFNAMSIZ]; - int i, j, ret=0, sendsize=1488, packet_num, offset = 0, port = 4445; - int fd; /* file descriptor for file to send */ - int outstanding; - struct timeval t_start,t_end; - ssize_t bytes, bytes_sent, bytes_in_pipe; - size_t total_bytes_sent = 0; - - struct sockaddr_in servaddr,cliaddr; - - - int filedes [2]; - ret = pipe (filedes); - - if (argc > 1) - packet_num = atoi(argv[1]); - else - packet_num = 166666*sendsize; - - if (argc > 2) - port = atoi(argv[2]); - - //sockfd = socket(AF_INET, SOCK_STREAM, 0); - //bzero(&servaddr,sizeof(servaddr)); - //servaddr.sin_family = AF_INET; - //servaddr.sin_addr.s_addr=inet_addr("128.111.68.220"); - //servaddr.sin_port=htons(4444); - - sockfd = socket(AF_INET, SOCK_STREAM, 0); - - bzero(&servaddr,sizeof(servaddr)); - servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr=inet_addr("128.111.68.220"); - servaddr.sin_port=htons(port); - - - fd = open("/data/local/tmp/bigfile_w", O_WRONLY | O_CREAT | O_TRUNC); - if (fd == -1) { - fprintf(stderr, "unable to open the file.\n"); - exit(1); - } - - //setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char *) &ret, sizeof(int)); - //ioctl(sockfd, SIOCOUTQ, &outstanding); - //printf("outstanding:%d\n", outstanding); - - gettimeofday(&t_start, NULL); - if (connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) - { - fprintf(stderr, "unable to connect the server.\n"); - exit(1); - } - while (total_bytes_sent < packet_num) - { - // Splice the data from in_fd into the pipe - if ((bytes_sent = splice(sockfd, NULL, filedes[1], NULL, - 4096, - SPLICE_F_MORE | SPLICE_F_MOVE)) <= 0) { - if (errno == EINTR || errno == EAGAIN) { - // Interrupted system call/try again - // Just skip to the top of the loop and try again - printf("in error: %d\n", bytes_sent); - fflush(stdout); - usleep(100); - continue; - } - perror("splice"); - return -1; - } - - //printf("%d\n", bytes_sent); - //fflush(stdout); - - - // Splice the data from the pipe into out_fd - bytes_in_pipe = bytes_sent; - while (bytes_in_pipe > 0) { - if ((bytes = splice(filedes[0], NULL, fd, NULL, bytes_in_pipe, - SPLICE_F_MORE | SPLICE_F_MOVE)) <= 0) { - if (errno == EINTR || errno == EAGAIN) { - // Interrupted system call/try again - // Just skip to the top of the loop and try again - printf("out error: %d\n", bytes_sent); - fflush(stdout); - continue; - } - perror("splice"); - return -1; - } - bytes_in_pipe -= bytes; - } - - //printf("%d, %d\n", bytes_sent, total_bytes_sent); - //fflush(stdout); - - total_bytes_sent += bytes_sent; - - /* - for(;;) - { - ioctl(sockfd, SIOCOUTQ, &outstanding); - printf("outstanding:%d\n", outstanding); - if (outstanding>0) - { - usleep(100); - } - else - { - break; - } - } - */ - - //ret = splice (fd, (off64_t *)&offset, filedes[1], NULL, sendsize, SPLICE_F_MORE | SPLICE_F_MOVE); - //ret = sendfile(sockfd, fd, (off_t *)&offset, sendsize); - //offset += total_bytes_sent; - //printf("sent:%d, total:%d\n", bytes_sent, total_bytes_sent); - } - close(sockfd); - gettimeofday(&t_end, NULL); - printf("%lf\n", (t_end.tv_sec-t_start.tv_sec)*1000.0+(t_end.tv_usec-t_start.tv_usec)/1000.0); - - close(fd); - - return 0; -} diff --git a/offloading_binaries/Splice_recv/splice_recv b/offloading_binaries/Splice_recv/splice_recv deleted file mode 100755 index a9fa812..0000000 Binary files a/offloading_binaries/Splice_recv/splice_recv and /dev/null differ diff --git a/offloading_binaries/Splice_recv_lo/Makefile b/offloading_binaries/Splice_recv_lo/Makefile deleted file mode 100644 index 55a3e25..0000000 --- a/offloading_binaries/Splice_recv_lo/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -CC = arm-linux-androideabi-gcc -CFLAGS = -pie -fPIE -TARGET = splice_recv_lo - -OBJS = $(patsubst %.c, %.o, $(wildcard *.c)) -HEADERS = $(wildcard *.h) - -all: $(TARGET) - -%.o: %.c $(HEADERS) - $(CC) $(CFLAGS) -c $< -o $@ - -.PRECIOUS: $(TARGET) $(OBJS) - -$(TARGET): $(OBJS) - $(CC) $(OBJS) -Wall $(CFLAGS) -o $@ - cp $(TARGET) /media/Lucifer/yanzi/projects/offloading/RDMAMobileDemo/app/src/main/assets/ -clean: - -rm -f *.o - -rm -f $(TARGET) diff --git a/offloading_binaries/Splice_recv_lo/main.c b/offloading_binaries/Splice_recv_lo/main.c deleted file mode 100644 index 4826c59..0000000 --- a/offloading_binaries/Splice_recv_lo/main.c +++ /dev/null @@ -1,176 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define _GNU_SOURCE /* See feature_test_macros(7) */ -#include -#include -#include - -#define ETH_P_IP 0x0800 /* Internet Protocol packet */ -#define ETH_ALEN 6 /* from */ -#define ETH_P_ALL 0x0003 - -#define MY_DEST_MAC0 0xba -#define MY_DEST_MAC1 0xf6 -#define MY_DEST_MAC2 0xb1 -#define MY_DEST_MAC3 0x71 -#define MY_DEST_MAC4 0x09 -#define MY_DEST_MAC5 0x64 - -#define DEFAULT_IF "wlan0" -#define BUF_SIZ 8192 - -int main(int argc, char *argv[]) -{ - int sockfd, listenfd; - socklen_t clilen; - struct ifreq if_idx; - struct ifreq if_mac; - int tx_len = 0; - char sendbuf[BUF_SIZ]; - struct ether_header *eh = (struct ether_header *) sendbuf; - struct iphdr *iph = (struct iphdr *) (sendbuf + sizeof(struct ether_header)); - struct sockaddr_ll socket_address; - char ifName[IFNAMSIZ]; - int i, j, ret=0, sendsize=1488, packet_num, offset = 0, port = 4445; - int fd; /* file descriptor for file to send */ - int outstanding; - struct timeval t_start,t_end; - ssize_t bytes, bytes_sent, bytes_in_pipe; - size_t total_bytes_sent = 0; - - struct sockaddr_in servaddr,cliaddr; - - - int filedes [2]; - ret = pipe (filedes); - - if (argc > 1) - packet_num = atoi(argv[1]); - else - packet_num = 166666*sendsize; - - if (argc > 2) - port = atoi(argv[2]); - - //sockfd = socket(AF_INET, SOCK_STREAM, 0); - //bzero(&servaddr,sizeof(servaddr)); - //servaddr.sin_family = AF_INET; - //servaddr.sin_addr.s_addr=inet_addr("128.111.68.220"); - //servaddr.sin_port=htons(4444); - - sockfd = socket(AF_INET, SOCK_STREAM, 0); - - bzero(&servaddr,sizeof(servaddr)); - servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr=inet_addr("192.168.1.15"); - servaddr.sin_port=htons(port); - - - fd = open("/data/local/tmp/bigfile_w", O_WRONLY | O_CREAT | O_TRUNC); - if (fd == -1) { - fprintf(stderr, "unable to open the file.\n"); - exit(1); - } - - //setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char *) &ret, sizeof(int)); - //ioctl(sockfd, SIOCOUTQ, &outstanding); - //printf("outstanding:%d\n", outstanding); - - gettimeofday(&t_start, NULL); - if (connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) - { - fprintf(stderr, "unable to connect the server.\n"); - exit(1); - } - while (total_bytes_sent < packet_num) - { - // Splice the data from in_fd into the pipe - if ((bytes_sent = splice(sockfd, NULL, filedes[1], NULL, - 4096, - SPLICE_F_MORE | SPLICE_F_MOVE)) <= 0) { - if (errno == EINTR || errno == EAGAIN) { - // Interrupted system call/try again - // Just skip to the top of the loop and try again - printf("in error: %d\n", bytes_sent); - fflush(stdout); - usleep(100); - continue; - } - perror("splice"); - return -1; - } - -// printf("%d\n", bytes_sent); -// fflush(stdout); - - // Splice the data from the pipe into out_fd - bytes_in_pipe = bytes_sent; - while (bytes_in_pipe > 0) { - if ((bytes = splice(filedes[0], NULL, fd, NULL, bytes_in_pipe, - SPLICE_F_MORE | SPLICE_F_MOVE)) <= 0) { - if (errno == EINTR || errno == EAGAIN) { - // Interrupted system call/try again - // Just skip to the top of the loop and try again - printf("out error: %d\n", bytes_sent); - fflush(stdout); - continue; - } - perror("splice"); - return -1; - } - bytes_in_pipe -= bytes; - } - -// printf("%d, %d\n", bytes_sent, total_bytes_sent); -// fflush(stdout); - - total_bytes_sent += bytes_sent; - - /* - for(;;) - { - ioctl(sockfd, SIOCOUTQ, &outstanding); - printf("outstanding:%d\n", outstanding); - if (outstanding>0) - { - usleep(100); - } - else - { - break; - } - } - */ - - //ret = splice (fd, (off64_t *)&offset, filedes[1], NULL, sendsize, SPLICE_F_MORE | SPLICE_F_MOVE); - //ret = sendfile(sockfd, fd, (off_t *)&offset, sendsize); - //offset += total_bytes_sent; - //printf("sent:%d, total:%d\n", bytes_sent, total_bytes_sent); - } - close(sockfd); - gettimeofday(&t_end, NULL); - printf("%lf\n", (t_end.tv_sec-t_start.tv_sec)*1000.0+(t_end.tv_usec-t_start.tv_usec)/1000.0); - - close(fd); - - return 0; -} diff --git a/offloading_binaries/Splice_recv_lo/main.o b/offloading_binaries/Splice_recv_lo/main.o deleted file mode 100644 index 9f831b1..0000000 Binary files a/offloading_binaries/Splice_recv_lo/main.o and /dev/null differ diff --git a/offloading_binaries/Splice_recv_lo/splice_recv_lo b/offloading_binaries/Splice_recv_lo/splice_recv_lo deleted file mode 100755 index 2950e70..0000000 Binary files a/offloading_binaries/Splice_recv_lo/splice_recv_lo and /dev/null differ diff --git a/offloading_binaries/client_recv_normaltcp/client_recv_normaltcp b/offloading_binaries/client_recv_normaltcp/client_recv_normaltcp index e27ac9e..3583e56 100755 Binary files a/offloading_binaries/client_recv_normaltcp/client_recv_normaltcp and b/offloading_binaries/client_recv_normaltcp/client_recv_normaltcp differ diff --git a/offloading_binaries/client_recv_normaltcp/main.c b/offloading_binaries/client_recv_normaltcp/main.c index 07d2a39..37e75bc 100644 --- a/offloading_binaries/client_recv_normaltcp/main.c +++ b/offloading_binaries/client_recv_normaltcp/main.c @@ -67,7 +67,7 @@ int main(int argc, char *argv[]) { fd = open(argv[4], O_WRONLY | O_CREAT | O_TRUNC); if (fd == -1) { - fprintf(stderr, "! Unable to open file %s.\n", argv[2]); + fprintf(stderr, "! Unable to open file %s.\n", argv[4]); close(sockfd); exit(1); } diff --git a/offloading_binaries/client_recv_normaltcp/main.o b/offloading_binaries/client_recv_normaltcp/main.o index 843865e..e22cc65 100644 Binary files a/offloading_binaries/client_recv_normaltcp/main.o and b/offloading_binaries/client_recv_normaltcp/main.o differ diff --git a/offloading_binaries/Splice_recv/Makefile b/offloading_binaries/client_recv_normaltcp_splice/Makefile similarity index 73% rename from offloading_binaries/Splice_recv/Makefile rename to offloading_binaries/client_recv_normaltcp_splice/Makefile index 253d69d..52cf339 100644 --- a/offloading_binaries/Splice_recv/Makefile +++ b/offloading_binaries/client_recv_normaltcp_splice/Makefile @@ -1,6 +1,7 @@ CC = arm-linux-androideabi-gcc +# CC = gcc CFLAGS = -pie -fPIE -TARGET = splice_recv +TARGET = client_recv_normaltcp_splice OBJS = $(patsubst %.c, %.o, $(wildcard *.c)) HEADERS = $(wildcard *.h) @@ -14,7 +15,7 @@ all: $(TARGET) $(TARGET): $(OBJS) $(CC) $(OBJS) -Wall $(CFLAGS) -o $@ - cp $(TARGET) /media/Lucifer/yanzi/projects/offloading/RDMAMobileDemo/app/src/main/assets/ + clean: -rm -f *.o -rm -f $(TARGET) diff --git a/offloading_binaries/client_recv_normaltcp_splice/client_recv_normaltcp_splice b/offloading_binaries/client_recv_normaltcp_splice/client_recv_normaltcp_splice new file mode 100755 index 0000000..510a475 Binary files /dev/null and b/offloading_binaries/client_recv_normaltcp_splice/client_recv_normaltcp_splice differ diff --git a/offloading_binaries/client_recv_normaltcp_splice/main.c b/offloading_binaries/client_recv_normaltcp_splice/main.c new file mode 100644 index 0000000..b93a213 --- /dev/null +++ b/offloading_binaries/client_recv_normaltcp_splice/main.c @@ -0,0 +1,140 @@ +/* + * Initial commit by Yibo @ Jul. 28, 2015 + * Last update by Yanzi @ Sept. 27, 2016 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define BUF_SIZ 65536 + +int main(int argc, char *argv[]) +{ + // defaults + uint total_bytes_recv = 0; + uint bytes, bytes_recv, bytes_in_pipe; + // for timing + double elapsedTime; + struct timeval t_start, t_end, t_now; + // for socket + int fd; // file descriptor of file to send + int sockfd; // socket + char recvbuf[BUF_SIZ]; + struct sockaddr_in servaddr; + // for misc + int ret; + int recvsize = 4096; + // create two pipes + int filedes[2]; + ret = pipe(filedes); + + if (argc < 3) + { + printf("Usage: %s <[optional] recvsize (bytes)> <[optional] filepath>\n", argv[0]); + exit(0); + } + + // set sendsize (if larger than 1460 will do packetization (fragmentation)) + if (argc > 3) + recvsize = atoi(argv[3]); + + // bind socket + sockfd = socket(AF_INET, SOCK_STREAM, 0); + bzero(&servaddr, sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = inet_addr(argv[2]); + servaddr.sin_port = htons(atoi(argv[3])); + + // connect socket + if (connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) + { + fprintf(stderr, "! Unable to connect the server.\n"); + exit(1); + } + + // if instrument to write to a file + if (argc > 4) + { + fd = open(argv[4], O_WRONLY | O_CREAT | O_TRUNC); + if (fd == -1) { + fprintf(stderr, "! Unable to open file %s.\n", argv[4]); + close(sockfd); + exit(1); + } + } + else + { + fd = open("/dev/null", O_WRONLY); + if (fd == -1) { + fprintf(stderr, "! Unable to open file %s.\n", argv[2]); + close(sockfd); + exit(1); + } + } + + // start timing + gettimeofday(&t_start, NULL); + + // start to receive + for (;;) + { + // printf("before: total_bytes_recv %d\n", total_bytes_recv); + + // Splice the data from in_fd into the pipe + if ((bytes_recv = splice(sockfd, NULL, filedes[1], NULL, + recvsize, SPLICE_F_MORE | SPLICE_F_MOVE)) <= 0) { + if (errno == EINTR || errno == EAGAIN) { + // Interrupted system call/try again + // Just skip to the top of the loop and try again + continue; + } + fprintf(stderr, "! splice error, errno: %d.\n", errno); + exit(1); + } + + // Splice the data from the pipe into out_fd + bytes_in_pipe = bytes_recv; + while (bytes_in_pipe > 0) { + if ((bytes = splice(filedes[0], NULL, fd, NULL, bytes_in_pipe, + SPLICE_F_MORE | SPLICE_F_MOVE)) <= 0) { + if (errno == EINTR || errno == EAGAIN) { + // Interrupted system call/try again + // Just skip to the top of the loop and try again + continue; + } + fprintf(stderr, "! splice error, errno: %d.\n", errno); + exit(1); + } + bytes_in_pipe -= bytes; + } + + total_bytes_recv += bytes_recv; + // printf("after: total_bytes_recv %d\n", total_bytes_recv); + } + + // end timing + gettimeofday(&t_end, NULL); + elapsedTime = (t_end.tv_sec - t_start.tv_sec) + (t_end.tv_usec - t_start.tv_usec) / 1000000.0; + printf( + "recv(bytes):%d\nduration(s):%lf\nthroughput(bps):%lf\n", + total_bytes_recv, elapsedTime, total_bytes_recv * 8 / elapsedTime); + + close(sockfd); + close(fd); + + return 0; +} diff --git a/offloading_binaries/client_recv_normaltcp_splice/main.o b/offloading_binaries/client_recv_normaltcp_splice/main.o new file mode 100644 index 0000000..2ab6da5 Binary files /dev/null and b/offloading_binaries/client_recv_normaltcp_splice/main.o differ diff --git a/offloading_binaries/client_recv_normaludp/client_recv_normaludp b/offloading_binaries/client_recv_normaludp/client_recv_normaludp index 107901d..8c0b0df 100755 Binary files a/offloading_binaries/client_recv_normaludp/client_recv_normaludp and b/offloading_binaries/client_recv_normaludp/client_recv_normaludp differ diff --git a/offloading_binaries/client_recv_normaludp/main.c b/offloading_binaries/client_recv_normaludp/main.c index 53255a7..08347fd 100644 --- a/offloading_binaries/client_recv_normaludp/main.c +++ b/offloading_binaries/client_recv_normaludp/main.c @@ -61,7 +61,7 @@ int main(int argc, char *argv[]) { fd = open(argv[4], O_WRONLY | O_CREAT | O_TRUNC); if (fd == -1) { - fprintf(stderr, "! Unable to open file %s.\n", argv[2]); + fprintf(stderr, "! Unable to open file %s.\n", argv[4]); close(sockfd); exit(1); } diff --git a/offloading_binaries/client_recv_normaludp/main.o b/offloading_binaries/client_recv_normaludp/main.o index 234f9db..ecc842a 100644 Binary files a/offloading_binaries/client_recv_normaludp/main.o and b/offloading_binaries/client_recv_normaludp/main.o differ diff --git a/offloading_binaries/client_send_bypassl3/client_send_bypassl3 b/offloading_binaries/client_send_bypassl3/client_send_bypassl3 index 593dace..5862418 100755 Binary files a/offloading_binaries/client_send_bypassl3/client_send_bypassl3 and b/offloading_binaries/client_send_bypassl3/client_send_bypassl3 differ diff --git a/offloading_binaries/client_send_bypassl3/main.c b/offloading_binaries/client_send_bypassl3/main.c index 2d228e8..8ec9fc6 100644 --- a/offloading_binaries/client_send_bypassl3/main.c +++ b/offloading_binaries/client_send_bypassl3/main.c @@ -31,7 +31,7 @@ #define MY_DEST_MAC4 0x86 #define MY_DEST_MAC5 0x52 -#define DEFAULT_IF "eth0" +#define DEFAULT_IF "wlan0" #define BUF_SIZ 4096 char isNumber(char number[]) @@ -169,7 +169,7 @@ int main(int argc, char *argv[]) &my_dest_mac[0], &my_dest_mac[1], &my_dest_mac[2], &my_dest_mac[3], &my_dest_mac[4], &my_dest_mac[5]); - printf("destMAC:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n", + printf("destMAC:%02x:%02x:%02x:%02x:%02x:%02x\n", my_dest_mac[0], my_dest_mac[1], my_dest_mac[2], my_dest_mac[3], my_dest_mac[4], my_dest_mac[5]); diff --git a/offloading_binaries/client_send_bypassl3/main.o b/offloading_binaries/client_send_bypassl3/main.o index 9c378b3..d11178d 100644 Binary files a/offloading_binaries/client_send_bypassl3/main.o and b/offloading_binaries/client_send_bypassl3/main.o differ diff --git a/offloading_binaries/makeall.sh b/offloading_binaries/makeall.sh index f7a96aa..f8d57e3 100644 --- a/offloading_binaries/makeall.sh +++ b/offloading_binaries/makeall.sh @@ -10,6 +10,8 @@ cd client_send_normaltcp && make cd ../ cd client_readfile_only && make cd ../ +cd client_recv_normaltcp_splice && make +cd ../ cd client_recv_normaltcp && make cd ../ cd client_recv_normaludp && make diff --git a/offloading_binaries/pushBinToDevice.sh b/offloading_binaries/pushBinToDevice.sh index 91c369e..975fa02 100755 --- a/offloading_binaries/pushBinToDevice.sh +++ b/offloading_binaries/pushBinToDevice.sh @@ -10,6 +10,8 @@ cd client_send_normaltcp && adb push client_send_normaltcp /data/local/tmp/ cd ../ cd client_readfile_only && adb push client_readfile_only /data/local/tmp/ cd ../ +cd client_recv_normaltcp_splice && adb push client_recv_normaltcp_splice /data/local/tmp/ +cd ../ cd client_recv_normaltcp && adb push client_recv_normaltcp /data/local/tmp/ cd ../ cd client_recv_normaludp && adb push client_recv_normaludp /data/local/tmp/