diff --git a/offloading_binaries/BypassL3_recv/bypassl3_recv b/offloading_binaries/BypassL3_recv/bypassl3_recv deleted file mode 100755 index 2c01307..0000000 Binary files a/offloading_binaries/BypassL3_recv/bypassl3_recv and /dev/null differ diff --git a/offloading_binaries/BypassL3_recv/main.c b/offloading_binaries/BypassL3_recv/main.c deleted file mode 100644 index ebbc6e7..0000000 --- a/offloading_binaries/BypassL3_recv/main.c +++ /dev/null @@ -1,125 +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 ETH_P_IP 0x0800 /* Internet Protocol packet */ -#define ETH_ALEN 6 /* from */ -#define ETH_P_ALL 0x0003 - -#define ETHER_TYPE 0x0800 /* Customize */ - -#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[]) -{ - struct iovec iov; - int sockfd, socktrigger; - int sockopt; - struct ifreq ifopts; /* set promiscuous mode */ - struct ifreq if_ip; /* get ip addr */ - ssize_t numbytes; - 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; - struct sockaddr_in servaddr; - char ifName[IFNAMSIZ]; - int i, j, ret, sendsize=1500, packet_num, offset = 0, port = 32000; - int fd; /* file descriptor for file to send */ - struct timeval t_start,t_end; - - /* Get interface name */ - strcpy(ifName, DEFAULT_IF); - - if (argc > 1) - packet_num = atoi(argv[1])/sendsize; - else - packet_num = 166666; - - sockfd = socket(AF_INET, SOCK_DGRAM, 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); - sendto(sockfd, "0\n",strlen("0\n"),0, (struct sockaddr *)&servaddr, sizeof(servaddr)); - - - if ((sockfd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) == -1) { - perror("listener: socket"); - return -1; - } - - strncpy(ifopts.ifr_name, ifName, IFNAMSIZ-1); - ioctl(sockfd, SIOCGIFFLAGS, &ifopts); - ifopts.ifr_flags |= IFF_PROMISC; - ioctl(sockfd, SIOCSIFFLAGS, &ifopts); - - if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &sockopt, sizeof sockopt) == -1) { - perror("setsockopt"); - close(sockfd); - exit(EXIT_FAILURE); - } - - if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE, ifName, IFNAMSIZ-1) == -1) { - perror("SO_BINDTODEVICE"); - close(sockfd); - exit(EXIT_FAILURE); - } - - - 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); - } - - /* Recv packet */ - gettimeofday(&t_start, NULL); - for (i = 0; i < packet_num;) - { - - numbytes = recvfrom(sockfd, sendbuf, sendsize, 0, NULL, NULL); - //printf("listener: got packet %lu bytes\n", numbytes); - - if (sendbuf[50] == '0') - { - write(fd, sendbuf, sendsize); - i++; - } - else - { - usleep(100); - } - } - 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); - - return 0; -} diff --git a/offloading_binaries/BypassL3_recv/main.o b/offloading_binaries/BypassL3_recv/main.o deleted file mode 100644 index b19ea68..0000000 Binary files a/offloading_binaries/BypassL3_recv/main.o and /dev/null differ diff --git a/offloading_binaries/BypassL3_recv/Makefile b/offloading_binaries/client_recv_bypassl3/Makefile similarity index 73% rename from offloading_binaries/BypassL3_recv/Makefile rename to offloading_binaries/client_recv_bypassl3/Makefile index e1bce73..831377a 100644 --- a/offloading_binaries/BypassL3_recv/Makefile +++ b/offloading_binaries/client_recv_bypassl3/Makefile @@ -1,6 +1,7 @@ CC = arm-linux-androideabi-gcc +# CC = gcc CFLAGS = -pie -fPIE -TARGET = bypassl3_recv +TARGET = client_recv_bypassl3 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_bypassl3/client_recv_bypassl3 b/offloading_binaries/client_recv_bypassl3/client_recv_bypassl3 new file mode 100755 index 0000000..b9b4ac1 Binary files /dev/null and b/offloading_binaries/client_recv_bypassl3/client_recv_bypassl3 differ diff --git a/offloading_binaries/client_recv_bypassl3/main.c b/offloading_binaries/client_recv_bypassl3/main.c new file mode 100644 index 0000000..dbadfe4 --- /dev/null +++ b/offloading_binaries/client_recv_bypassl3/main.c @@ -0,0 +1,193 @@ +/* + * Initial commit by Yibo @ Jul. 28, 2015 + * Last update by Yanzi @ Sept. 28, 2016 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 0x18 +#define MY_DEST_MAC1 0x03 +#define MY_DEST_MAC2 0x73 +#define MY_DEST_MAC3 0xc8 +#define MY_DEST_MAC4 0x86 +#define MY_DEST_MAC5 0x52 + +#define DEFAULT_IF "wlan0" +#define BUF_SIZ 65535 + +char isNumber(char number[]) +{ + int i = 0; + + //checking for negative numbers + if (number[0] == '-') + i = 1; + for (; number[i] != 0; i++) + { + //if (number[i] > '9' || number[i] < '0') + if (!isdigit(number[i])) + return 0; + } + return 1; +} + +int main(int argc, char *argv[]) +{ + // defaults + uint total_bytes_recv = 0; + // for timing + double elapsedTime; + struct timeval t_start, t_end, t_now; + // for socket + int i, j, fd; // file descriptor of file to send + int sockfd; // socket + int sockopt; + char recvbuf[BUF_SIZ]; + struct ifreq ifopts; + struct ifreq if_mac; + struct sockaddr_in servaddr; + char ifName[IFNAMSIZ]; + // for misc + int ret; + int recvsize = 1500; // 1500 MTU (raw socket) + int bytes2send = 0; + struct stat st; + unsigned char my_dest_mac[6]; + + if (argc < 3) + { + printf("Usage: %s <[optional] recvsize (bytes)> <[optional] interface> <[optional] filepath>\n", argv[0]); + exit(0); + } + + // set recvsize (if larger than 1460 will do packetization (fragmentation)) + if (argc > 3) + recvsize = atoi(argv[3]); + + // set interface + if (argc > 4) { + strcpy(ifName, argv[4]); + } else { + strcpy(ifName, DEFAULT_IF); + } + + // bind socket and send a trigger (UDP) + sockfd = socket(AF_INET, SOCK_DGRAM, 0); + bzero(&servaddr, sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = inet_addr(argv[1]); + servaddr.sin_port = htons(atoi(argv[2])); + ret = sendto(sockfd, "!?=\n", 4, 0, (struct sockaddr *)&servaddr, sizeof(servaddr)); + if (ret <= 0) + { + printf("! Trigger the initialization"); + } + + if ((sockfd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) == -1) + { + fprintf(stderr, "! raw socket error.\n"); + exit(1); + } + + // Get the index of the interface to receive from + memset(&ifopts, 0, sizeof(struct ifreq)); + strncpy(ifopts.ifr_name, ifName, IFNAMSIZ-1); + if (ioctl(sockfd, SIOCGIFFLAGS, &ifopts) < 0) + { + fprintf(stderr, "! SIOCGIFFLAGS error. Check permission.\n"); + exit(EXIT_FAILURE); + } + ifopts.ifr_flags |= IFF_PROMISC; + if (ioctl(sockfd, SIOCSIFFLAGS, &ifopts) < 0) + { + fprintf(stderr, "! SIOCSIFFLAGS error. Check permission.\n"); + exit(EXIT_FAILURE); + } + + if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &sockopt, sizeof sockopt) == -1) { + fprintf(stderr, "! setsockopt error. \n"); + close(sockfd); + exit(EXIT_FAILURE); + } + + if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE, ifName, IFNAMSIZ-1) == -1) { + fprintf(stderr, "! SO_BINDTODEVICE error. \n"); + close(sockfd); + exit(EXIT_FAILURE); + } + + // if instrument to write to a file + if (argc > 5) + { + fd = open(argv[5], O_WRONLY | O_CREAT | O_TRUNC); + if (fd == -1) { + fprintf(stderr, "! Unable to open file %s.\n", argv[5]); + close(sockfd); + exit(1); + } + } + + // start timing + gettimeofday(&t_start, NULL); + + // start to receive + for (;;) + { + // TODO: need a method to distinguish between other packets and rawsocket packets + // printf("before: total_bytes_recv %d\n", total_bytes_recv); + ret = recvfrom(sockfd, recvbuf, recvsize, 0, NULL, NULL); + + if (ret <= 0) + { + if (errno == 0) + break; + fprintf(stderr, "! Fail to recv: ret:%d, err:%d; quiting..\n", ret, errno); + exit(1); + } + + // a "code" to indicate rawsocket is done + // printf("%d %d %d", (recvbuf[0] == '='), (recvbuf[1] == '?'), (recvbuf[0] == '!')); + if ((recvbuf[0] == '=') && (recvbuf[1] == '?') && (recvbuf[2] == '!')) + break; + + // write to file if specified filename + if (argc > 5) + write(fd, recvbuf, ret); + + // count how many bytes received + total_bytes_recv += ret; + 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( + "sent(bytes):%d\nduration(s):%lf\nthroughput(bps):%lf\n", + total_bytes_recv, elapsedTime, total_bytes_recv * 8 / elapsedTime); + + close(sockfd); + if (argc > 5) + close(fd); + + return 0; +} diff --git a/offloading_binaries/client_recv_bypassl3/main.o b/offloading_binaries/client_recv_bypassl3/main.o new file mode 100644 index 0000000..7e34bcf Binary files /dev/null and b/offloading_binaries/client_recv_bypassl3/main.o differ diff --git a/offloading_binaries/makeall.sh b/offloading_binaries/makeall.sh index ed1b030..c2ae331 100644 --- a/offloading_binaries/makeall.sh +++ b/offloading_binaries/makeall.sh @@ -15,6 +15,8 @@ cd ../ # client receiver cd client_recv_normaltcp_splice && make cd ../ +cd client_recv_bypassl3 && 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 975fa02..03466bc 100755 --- a/offloading_binaries/pushBinToDevice.sh +++ b/offloading_binaries/pushBinToDevice.sh @@ -12,6 +12,8 @@ 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_bypassl3 && adb push client_recv_bypassl3 /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/