diff --git a/offloading_binaries/BypassL3Binary/main.c b/offloading_binaries/BypassL3Binary/main.c deleted file mode 100644 index fba88fe..0000000 --- a/offloading_binaries/BypassL3Binary/main.c +++ /dev/null @@ -1,206 +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 - -#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 DEFAULT_IF "eth1" -#define BUF_SIZ 8192 - -int main(int argc, char *argv[]) -{ - int slotLength = 10000; // in microseconds - int quota = 1000000000; // Bytes per slot, default 1GB/slot - int sentInSlot = 0, slot = 1; - double elapsedTime; - double packetPerSlot; - - struct iovec iov; - int sockfd; - 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, sendsize=1500, packet_num, offset = 0; - int fd; /* file descriptor for file to send */ - struct timeval t_start, t_end, t_now; - - if (argc > 4) - sendsize = atoi(argv[4]); - - if (argc > 1) - packet_num = atoi(argv[1])/sendsize; - else - packet_num = 166666; - - if (argc > 2) - quota = atoi(argv[2]) / (1000000 / slotLength); - else { - printf("Usage: ./bypassl3 "); - exit(-1); - } - - if (argc > 3) { - /* get the name of the interface */ - strcpy(ifName, argv[3]); - } else { - strcpy(ifName, DEFAULT_IF); - } - - // fix packet size problem - packetPerSlot = ceil(((double)quota) / sendsize); - slotLength = (int)(packetPerSlot * sendsize / quota * slotLength); - quota = (int)packetPerSlot * sendsize; - - - /* Open RAW socket to send on */ - //sendsize -= 14; - //if ((sockfd = socket(AF_PACKET, SOCK_DGRAM, IPPROTO_RAW)) == -1) { - if ((sockfd = socket(AF_PACKET, SOCK_RAW, IPPROTO_RAW)) == -1) { - perror("socket"); - } - - /* Get the index of the interface to send on */ - memset(&if_idx, 0, sizeof(struct ifreq)); - strncpy(if_idx.ifr_name, ifName, IFNAMSIZ-1); - if (ioctl(sockfd, SIOCGIFINDEX, &if_idx) < 0) - perror("SIOCGIFINDEX"); - /* Get the MAC address of the interface to send on */ - memset(&if_mac, 0, sizeof(struct ifreq)); - strncpy(if_mac.ifr_name, ifName, IFNAMSIZ-1); - if (ioctl(sockfd, SIOCGIFHWADDR, &if_mac) < 0) - perror("SIOCGIFHWADDR"); - - /* Construct the Ethernet header */ - memset(sendbuf, 0, BUF_SIZ); - /* Ethernet header */ - - eh->ether_shost[0] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[0]; - eh->ether_shost[1] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[1]; - eh->ether_shost[2] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[2]; - eh->ether_shost[3] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[3]; - eh->ether_shost[4] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[4]; - eh->ether_shost[5] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[5]; - eh->ether_dhost[0] = MY_DEST_MAC0; - eh->ether_dhost[1] = MY_DEST_MAC1; - eh->ether_dhost[2] = MY_DEST_MAC2; - eh->ether_dhost[3] = MY_DEST_MAC3; - eh->ether_dhost[4] = MY_DEST_MAC4; - eh->ether_dhost[5] = MY_DEST_MAC5; - eh->ether_type = htons(ETH_P_IP); - tx_len += sizeof(struct ether_header); - - - /* Packet data */ - /* - sendbuf[tx_len++] = 0xde; - sendbuf[tx_len++] = 0xad; - sendbuf[tx_len++] = 0xbe; - sendbuf[tx_len++] = 0xef; - */ - - /* Index of the network device */ - socket_address.sll_ifindex = if_idx.ifr_ifindex; - /* Address length*/ - socket_address.sll_halen = ETH_ALEN; - /* Destination MAC */ - socket_address.sll_addr[0] = MY_DEST_MAC0; - socket_address.sll_addr[1] = MY_DEST_MAC1; - socket_address.sll_addr[2] = MY_DEST_MAC2; - socket_address.sll_addr[3] = MY_DEST_MAC3; - socket_address.sll_addr[4] = MY_DEST_MAC4; - socket_address.sll_addr[5] = MY_DEST_MAC5; - //test - //socket_address.sll_family = AF_PACKET; - //socket_address.sll_protocol = htons(ETH_P_ALL); - -// fd = open("bigfile"); - fd = open("/data/local/tmp/bigfile", O_RDONLY); - if (fd == -1) { - fprintf(stderr, "unable to open the file.\n"); - exit(1); - } - - /* - if (bind(sockfd,(struct sockaddr*)&socket_address, sizeof(struct sockaddr_ll)) == -1) - { - perror("bind error.\n"); - exit(1); - } - */ - /* Send packet */ - gettimeofday(&t_start, NULL); - read(fd, sendbuf+tx_len, sendsize-tx_len); - for (i = 0; i < packet_num;) - { - if (((packet_num - i) * sendsize) < quota) - { - quota = (packet_num - i) * sendsize; - } - - while (sentInSlot < quota) - { - //ret = sendfile(sockfd, fd, (off_t *)&offset, sendsize); - //printf("%d\t%d\n", ret, errno); - //read(fd, sendbuf, sendsize); - ret = sendto(sockfd, sendbuf, sendsize, MSG_DONTWAIT, (struct sockaddr*)&socket_address, sizeof(struct sockaddr_ll)); -// printf("%d\t%d\n", ret, errno); - if (ret == sendsize) - { - read(fd, sendbuf+tx_len, sendsize-tx_len); - i++; - sentInSlot = sentInSlot + ret; - } - else - { - //printf("sendto error\n"); - usleep(100); - } - } - gettimeofday(&t_now, NULL); - elapsedTime = (t_now.tv_sec-t_start.tv_sec)*1000000.0+(t_now.tv_usec-t_start.tv_usec); - if (elapsedTime < slotLength * slot) - { - //printf("sent %d, quota %d, packet_num %d, usleep %lf\n", i, quota, packet_num, slotLength * slot - elapsedTime); - usleep((int)(slotLength * slot - elapsedTime)); - } - sentInSlot = 0; - slot++; - } - 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/Normal_donothing/Makefile b/offloading_binaries/Normal_donothing/Makefile deleted file mode 100644 index a15cbec..0000000 --- a/offloading_binaries/Normal_donothing/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -CC = arm-linux-androideabi-gcc -CFLAGS = -pie -fPIE -llog -TARGET = normal_readonly - -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/mobileOffloading/RDMAMobileDemo/app/src/main/assets/ - -clean: - -rm -f *.o - -rm -f $(TARGET) diff --git a/offloading_binaries/Normal_donothing/main.c b/offloading_binaries/Normal_donothing/main.c deleted file mode 100644 index 2b8bc44..0000000 --- a/offloading_binaries/Normal_donothing/main.c +++ /dev/null @@ -1,130 +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 -#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 DEFAULT_IF "eth0" -#define BUF_SIZ 8192 - -int main(int argc, char *argv[]) -{ - int slotLength = 10000; // in microseconds - int quota = 1000000000; // Bytes per slot, default 1GB/slot - int sentInSlot = 0, slot = 1; - double elapsedTime; - - struct iovec iov; - int sockfd; - 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, sendsize=1488, packet_num, offset = 0; - int fd; /* file descriptor for file to send */ - struct timeval t_start,t_end,t_now; - - struct sockaddr_in servaddr; - -monstartup("normal_readonly.so"); - if (argc > 1) - packet_num = atoi(argv[1]); - else - packet_num = 166666*sendsize; - - if (argc > 2) - quota = atoi(argv[2]) / (1000000 / slotLength); - -// 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); - - - - fd = open("/data/local/tmp/bigfile", O_RDONLY); - if (fd == -1) { - fprintf(stderr, "unable to open the file.\n"); - exit(1); - } - - gettimeofday(&t_start, NULL); -// if (connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) -// { -// fprintf(stderr, "unable to connect the server.\n"); -// exit(1); -// } - while (offset < packet_num) - { - if ((packet_num - offset) < quota) - { - quota = packet_num - offset; - } - while (sentInSlot < quota) - { - read(fd, sendbuf, (quota - sentInSlot < 4096) ? quota - sentInSlot : 4096); - //ret = send(sockfd, sendbuf, (quota - sentInSlot < 4096) ? quota - sentInSlot : 4096, 0); - //if (ret <= 0) - //{ - // printf("send fail\n"); - // usleep(100); - // continue; - //} - ret = 100; - offset += ret; - sentInSlot = sentInSlot + ret; - } - gettimeofday(&t_now, NULL); - elapsedTime = (t_now.tv_sec-t_start.tv_sec)*1000000.0+(t_now.tv_usec-t_start.tv_usec); - if (elapsedTime < slotLength * slot) - { - //printf("sent %d, quota %d, packet_num %d, usleep %lf\n", offset, quota, packet_num, slotLength * slot - elapsedTime); - usleep((int)(slotLength * slot - elapsedTime)); - } - sentInSlot = 0; - slot++; - - } -// 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); -moncleanup(); - return 0; -} diff --git a/offloading_binaries/Normal_donothing/normal_readonly b/offloading_binaries/Normal_donothing/normal_readonly deleted file mode 100755 index 6052a63..0000000 Binary files a/offloading_binaries/Normal_donothing/normal_readonly and /dev/null differ diff --git a/offloading_binaries/Normal_lo/Makefile b/offloading_binaries/Normal_lo/Makefile deleted file mode 100644 index e92bc6b..0000000 --- a/offloading_binaries/Normal_lo/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -CC = arm-linux-androideabi-gcc -CFLAGS = -pie -fPIE -llog -#STATICLIB = -llog -l/media/Lucifer/android/ndk-profiler/obj/local/armeabi-v7a/libandroid-ndk-profiler.a -TARGET = normal_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) - -#$(call import-module,android-ndk-profiler) diff --git a/offloading_binaries/Normal_lo/main.c b/offloading_binaries/Normal_lo/main.c deleted file mode 100644 index de3d00f..0000000 --- a/offloading_binaries/Normal_lo/main.c +++ /dev/null @@ -1,131 +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 -//#include "/media/Lucifer/android/ndk-profiler/jni/prof.h" - -#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 slotLength = 10000; // in microseconds - int quota = 1000000000; // Bytes per slot, default 1GB/slot - int sentInSlot = 0, slot = 1; - double elapsedTime; - - struct iovec iov; - int sockfd; - 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, sendsize=1488, packet_num, offset = 0; - int fd; /* file descriptor for file to send */ - struct timeval t_start,t_end,t_now; - - struct sockaddr_in servaddr; - -// monstartup("normal"); - - if (argc > 1) - packet_num = atoi(argv[1]); - else - packet_num = 166666*sendsize; - - if (argc > 2) - quota = atoi(argv[2]) / (1000000 / slotLength); - - 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(4444); - - - - fd = open("/data/local/tmp/bigfile", O_RDONLY); - if (fd == -1) { - fprintf(stderr, "unable to open the file.\n"); - exit(1); - } - - gettimeofday(&t_start, NULL); - if (connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) - { - fprintf(stderr, "unable to connect the server.\n"); - exit(1); - } - while (offset < packet_num) - { - if ((packet_num - offset) < quota) - { - quota = packet_num - offset; - } - while (sentInSlot < quota) - { - read(fd, sendbuf, (quota - sentInSlot < 4096) ? quota - sentInSlot : 4096); - ret = send(sockfd, sendbuf, (quota - sentInSlot < 4096) ? quota - sentInSlot : 4096, 0); -// printf("%d\t%d\n", ret, errno); - if (ret <= 0) - { - printf("send fail\n"); - usleep(100); - continue; - } - offset += ret; - sentInSlot = sentInSlot + ret; - } - gettimeofday(&t_now, NULL); - elapsedTime = (t_now.tv_sec-t_start.tv_sec)*1000000.0+(t_now.tv_usec-t_start.tv_usec); - if (elapsedTime < slotLength * slot) - { - //printf("sent %d, quota %d, packet_num %d, usleep %lf\n", offset, quota, packet_num, slotLength * slot - elapsedTime); - usleep((int)(slotLength * slot - elapsedTime)); - } - sentInSlot = 0; - slot++; - - } - 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); - -// moncleanup(); - return 0; -} diff --git a/offloading_binaries/Normal_lo/main.o b/offloading_binaries/Normal_lo/main.o deleted file mode 100644 index 53f3881..0000000 Binary files a/offloading_binaries/Normal_lo/main.o and /dev/null differ diff --git a/offloading_binaries/Normal_memory/main.c b/offloading_binaries/Normal_memory/main.c deleted file mode 100644 index e30688b..0000000 --- a/offloading_binaries/Normal_memory/main.c +++ /dev/null @@ -1,100 +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 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; - 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, sendsize=1488, packet_num, offset = 0; - int fd; /* file descriptor for file to send */ - struct timeval t_start,t_end; - - struct sockaddr_in servaddr; - - if (argc > 1) - packet_num = atoi(argv[1])*sendsize; - else - packet_num = 166666*sendsize; - - 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); - - - - fd = open("/data/local/tmp/bigfile"); - if (fd == -1) { - fprintf(stderr, "unable to open the file.\n"); - exit(1); - } - read(fd, sendbuf, 4096); - - gettimeofday(&t_start, NULL); - if (connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) - { - fprintf(stderr, "unable to connect the server.\n"); - exit(1); - } - while (offset < packet_num) - { - ret = send(sockfd, sendbuf, 4096, 0); - if (ret <= 0) - { - printf("send fail\n"); - usleep(100); - continue; - } - offset += ret; - } - 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/Normal_memory/normal_memory b/offloading_binaries/Normal_memory/normal_memory deleted file mode 100755 index 259244d..0000000 Binary files a/offloading_binaries/Normal_memory/normal_memory and /dev/null differ diff --git a/offloading_binaries/Normal_udp/main.c b/offloading_binaries/Normal_udp/main.c deleted file mode 100644 index e226700..0000000 --- a/offloading_binaries/Normal_udp/main.c +++ /dev/null @@ -1,123 +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 -#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 slotLength = 10000; // in microseconds - int quota = 1000000000; // Bytes per slot, default 1GB/slot - int sentInSlot = 0, slot = 1; - double elapsedTime; - double packetPerSlot; - - struct iovec iov; - int sockfd, listenfd; - 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, sendsize=1458, packet_num, offset = 0, port; - int fd; /* file descriptor for file to send */ - struct sockaddr_in servaddr,cliaddr; - socklen_t clilen; - struct timeval t_start,t_end,t_now; - if (argc > 1) - packet_num = atoi(argv[1]); - else - packet_num = 166666*sendsize; - - if (argc > 2) - quota = atoi(argv[2]) / (1000000 / slotLength); - else - { - printf("Usage: UDPSender bytes rate"); - exit(1); - } - - // fix packet size problem - packetPerSlot = ceil(((double)quota) / sendsize); - slotLength = (int)(packetPerSlot * sendsize / quota * slotLength); - quota = (int)packetPerSlot * sendsize; - - 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(9876); - - gettimeofday(&t_start, NULL); - while (offset < packet_num) - { - if ((packet_num - offset) < quota) - { - quota = packet_num - offset; - } - while (sentInSlot < quota) - { - ret = sendto(sockfd, sendbuf, sendsize, 0, (struct sockaddr *)&servaddr, sizeof(servaddr)); - if (ret < sendsize) - { - printf("send fail\n"); - usleep(100); - continue; - } - offset += ret; - sentInSlot = sentInSlot + ret; - } - gettimeofday(&t_now, NULL); - elapsedTime = (t_now.tv_sec-t_start.tv_sec)*1000000.0+(t_now.tv_usec-t_start.tv_usec); - //printf("sent %d, quota %d, packet_num %d, usleep %lf\n", offset, quota, packet_num, slotLength * slot - elapsedTime); - if (elapsedTime < slotLength * slot) - { - usleep((int)(slotLength * slot - elapsedTime)); - } - sentInSlot = 0; - slot++; - - } - 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/Normal_udp/main.o b/offloading_binaries/Normal_udp/main.o deleted file mode 100644 index cefe867..0000000 Binary files a/offloading_binaries/Normal_udp/main.o and /dev/null differ diff --git a/offloading_binaries/Normal_udp/normal_udp b/offloading_binaries/Normal_udp/normal_udp deleted file mode 100755 index efdea1a..0000000 Binary files a/offloading_binaries/Normal_udp/normal_udp and /dev/null differ diff --git a/offloading_binaries/Normal_udp_lo/Makefile b/offloading_binaries/Normal_udp_lo/Makefile deleted file mode 100644 index 5c13655..0000000 --- a/offloading_binaries/Normal_udp_lo/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -CC = arm-linux-androideabi-gcc -#CC = gcc -CFLAGS = -pie -fPIE -lm -TARGET = normal_udp_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/Normal_udp_lo/main.c b/offloading_binaries/Normal_udp_lo/main.c deleted file mode 100644 index ab72016..0000000 --- a/offloading_binaries/Normal_udp_lo/main.c +++ /dev/null @@ -1,124 +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 -#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 327680 - -int main(int argc, char *argv[]) -{ - int slotLength = 10000; // in microseconds - int quota = 1000000000; // Bytes per slot, default 1GB/slot - int sentInSlot = 0, slot = 1; - double elapsedTime; - double packetPerSlot; - - struct iovec iov; - int sockfd, listenfd; - 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, sendsize=58320, packet_num, offset = 0, port; - int fd; /* file descriptor for file to send */ - struct sockaddr_in servaddr,cliaddr; - socklen_t clilen; - struct timeval t_start,t_end,t_now; - if (argc > 1) - packet_num = atoi(argv[1]); - else - packet_num = 166666*sendsize; - - if (argc > 2) - quota = atoi(argv[2]) / (1000000 / slotLength); - else - { - printf("Usage: UDPSender bytes rate"); - exit(1); - } - - // fix packet size problem - packetPerSlot = ceil(((double)quota) / sendsize); - slotLength = (int)(packetPerSlot * sendsize / quota * slotLength); - quota = (int)packetPerSlot * sendsize; - - sockfd=socket(AF_INET, SOCK_DGRAM, 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(9876); - - gettimeofday(&t_start, NULL); - while (offset < packet_num) - { - if ((packet_num - offset) < quota) - { - quota = packet_num - offset; - } - while (sentInSlot < quota) - { - ret = sendto(sockfd, sendbuf, sendsize, 0, (struct sockaddr *)&servaddr, sizeof(servaddr)); -// printf("%d, %d\n", ret, errno); - if (ret < sendsize) - { - printf("send fail\n"); - usleep(100); - continue; - } - offset += ret; - sentInSlot = sentInSlot + ret; - } - gettimeofday(&t_now, NULL); - elapsedTime = (t_now.tv_sec-t_start.tv_sec)*1000000.0+(t_now.tv_usec-t_start.tv_usec); - //printf("sent %d, quota %d, packet_num %d, usleep %lf\n", offset, quota, packet_num, slotLength * slot - elapsedTime); - if (elapsedTime < slotLength * slot) - { - usleep((int)(slotLength * slot - elapsedTime)); - } - sentInSlot = 0; - slot++; - - } - 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/Normal_udp_lo/main.o b/offloading_binaries/Normal_udp_lo/main.o deleted file mode 100644 index 297265b..0000000 Binary files a/offloading_binaries/Normal_udp_lo/main.o and /dev/null differ diff --git a/offloading_binaries/Normal_udp_lo/normal_udp_lo b/offloading_binaries/Normal_udp_lo/normal_udp_lo deleted file mode 100755 index 8475673..0000000 Binary files a/offloading_binaries/Normal_udp_lo/normal_udp_lo and /dev/null differ diff --git a/offloading_binaries/Normal_udp_usb/Makefile b/offloading_binaries/Normal_udp_usb/Makefile deleted file mode 100644 index 87d82c4..0000000 --- a/offloading_binaries/Normal_udp_usb/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -CC = arm-linux-androideabi-gcc -#CC = gcc -CFLAGS = -pie -fPIE -lm -TARGET = normal_udp_usb - -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/Normal_udp_usb/main.c b/offloading_binaries/Normal_udp_usb/main.c deleted file mode 100644 index d7bda03..0000000 --- a/offloading_binaries/Normal_udp_usb/main.c +++ /dev/null @@ -1,124 +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 -#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 "usb0" -#define BUF_SIZ 8192 - -int main(int argc, char *argv[]) -{ - int slotLength = 10000; // in microseconds - int quota = 1000000000; // Bytes per slot, default 1GB/slot - int sentInSlot = 0, slot = 1; - double elapsedTime; - double packetPerSlot; - - struct iovec iov; - int sockfd, listenfd; - 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, sendsize=1458, packet_num, offset = 0, port; - int fd; /* file descriptor for file to send */ - struct sockaddr_in servaddr,cliaddr; - socklen_t clilen; - struct timeval t_start,t_end,t_now; - if (argc > 1) - packet_num = atoi(argv[1]); - else - packet_num = 166666*sendsize; - - if (argc > 2) - quota = atoi(argv[2]) / (1000000 / slotLength); - else - { - printf("Usage: UDPSender bytes rate"); - exit(1); - } - - // fix packet size problem - packetPerSlot = ceil(((double)quota) / sendsize); - slotLength = (int)(packetPerSlot * sendsize / quota * slotLength); - quota = (int)packetPerSlot * sendsize; - - sockfd=socket(AF_INET, SOCK_DGRAM, 0); - bzero(&servaddr,sizeof(servaddr)); - servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr=inet_addr("10.42.0.1"); - servaddr.sin_port=htons(9876); - - gettimeofday(&t_start, NULL); - while (offset < packet_num) - { - if ((packet_num - offset) < quota) - { - quota = packet_num - offset; - } - while (sentInSlot < quota) - { - ret = sendto(sockfd, sendbuf, sendsize, 0, (struct sockaddr *)&servaddr, sizeof(servaddr)); -// printf("%d, %d\n", ret, errno); - if (ret < sendsize) - { - printf("send fail\n"); - usleep(100); - continue; - } - offset += ret; - sentInSlot = sentInSlot + ret; - } - gettimeofday(&t_now, NULL); - elapsedTime = (t_now.tv_sec-t_start.tv_sec)*1000000.0+(t_now.tv_usec-t_start.tv_usec); - //printf("sent %d, quota %d, packet_num %d, usleep %lf\n", offset, quota, packet_num, slotLength * slot - elapsedTime); - if (elapsedTime < slotLength * slot) - { - usleep((int)(slotLength * slot - elapsedTime)); - } - sentInSlot = 0; - slot++; - - } - 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/Normal_udp_usb/main.o b/offloading_binaries/Normal_udp_usb/main.o deleted file mode 100644 index c07d53f..0000000 Binary files a/offloading_binaries/Normal_udp_usb/main.o and /dev/null differ diff --git a/offloading_binaries/Normal_memory/Makefile b/offloading_binaries/c2s_bypassl3/Makefile similarity index 73% rename from offloading_binaries/Normal_memory/Makefile rename to offloading_binaries/c2s_bypassl3/Makefile index 792847a..f513991 100644 --- a/offloading_binaries/Normal_memory/Makefile +++ b/offloading_binaries/c2s_bypassl3/Makefile @@ -1,6 +1,7 @@ CC = arm-linux-androideabi-gcc +# CC = gcc CFLAGS = -pie -fPIE -TARGET = normal_memory +TARGET = c2s_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/BypassL3Binary/bypassl3 b/offloading_binaries/c2s_bypassl3/c2s_bypassl3 similarity index 51% rename from offloading_binaries/BypassL3Binary/bypassl3 rename to offloading_binaries/c2s_bypassl3/c2s_bypassl3 index 5189a90..4e18bfc 100755 Binary files a/offloading_binaries/BypassL3Binary/bypassl3 and b/offloading_binaries/c2s_bypassl3/c2s_bypassl3 differ diff --git a/offloading_binaries/c2s_bypassl3/main.c b/offloading_binaries/c2s_bypassl3/main.c new file mode 100644 index 0000000..a225072 --- /dev/null +++ b/offloading_binaries/c2s_bypassl3/main.c @@ -0,0 +1,254 @@ +/* + * Initial commit by Yibo @ Jul. 28, 2015 + * Last update by Yanzi @ Sept. 26, 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 "eth0" +#define BUF_SIZ 4096 + +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 slotLength = 10000; // in microseconds, for bandwidth control + uint quota = 1000000000; // default bytes per slot, default 1GB/slot + uint sentInSlot = 0, slot = 1; + uint total_bytes_sent = 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 tx_len = 0; + char sendbuf[BUF_SIZ]; + struct ifreq if_idx; + struct ifreq if_mac; + struct sockaddr_in servaddr; + 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]; + // for misc + int ret; + int sendsize = 1500; // 1500 MTU (raw socket) + int bytes2send = 0; + struct stat st; + + if (argc < 2) + { + printf("Usage: %s <[optional] bandwidth (bps)> <[optional] sendsize (bytes)> <[optional] interface>\n", argv[0]); + exit(0); + } + + // set bandwidth + if (argc > 2) + quota = atoi(argv[2]) / 8 / (1000000 / slotLength); + + // set sendsize (if larger than 1460 will do packetization (fragmentation)) + if (argc > 3) + sendsize = atoi(argv[3]); + + // set interface + if (argc > 4) { + strcpy(ifName, argv[4]); + } else { + strcpy(ifName, DEFAULT_IF); + } + + // get file size (bytes2send) + if (isNumber(argv[1])) + { + // set bytes to send + bytes2send = atoi(argv[1]); + // open file descriptor + fd = open("/data/local/tmp/bigfile", O_RDONLY); + if (fd == -1) + { + fprintf(stderr, "! Unable to open /data/local/tmp/bigfile.\n"); + exit(1); + } + } + else + { + // open file descriptor + fd = open(argv[1], O_RDONLY); + if (fd == -1) + { + fprintf(stderr, "! Unable to open file %s.\n", argv[1]); + exit(1); + } + fstat(fd, &st); + bytes2send = st.st_size; + printf("bytes2send:%d\n", bytes2send); + } + + if ((sockfd = socket(AF_PACKET, SOCK_RAW, IPPROTO_RAW)) == -1) + { + fprintf(stderr, "! raw socket error.\n"); + exit(1); + } + + // Get the index of the interface to send on + memset(&if_idx, 0, sizeof(struct ifreq)); + strncpy(if_idx.ifr_name, ifName, IFNAMSIZ - 1); + if (ioctl(sockfd, SIOCGIFINDEX, &if_idx) < 0) + { + fprintf(stderr, "! SIOCGIFINDEX error. Check permission.\n"); + exit(1); + } + + // Get the MAC address of the interface to send on + memset(&if_mac, 0, sizeof(struct ifreq)); + strncpy(if_mac.ifr_name, ifName, IFNAMSIZ - 1); + if (ioctl(sockfd, SIOCGIFHWADDR, &if_mac) < 0) + { + fprintf(stderr, "! SIOCGIFHWADDR error. Check permission.\n"); + exit(1); + } + + // Set mem + memset(sendbuf, 0, BUF_SIZ); + + // Construct the Ethernet header + eh->ether_shost[0] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[0]; + eh->ether_shost[1] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[1]; + eh->ether_shost[2] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[2]; + eh->ether_shost[3] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[3]; + eh->ether_shost[4] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[4]; + eh->ether_shost[5] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[5]; + eh->ether_dhost[0] = MY_DEST_MAC0; + eh->ether_dhost[1] = MY_DEST_MAC1; + eh->ether_dhost[2] = MY_DEST_MAC2; + eh->ether_dhost[3] = MY_DEST_MAC3; + eh->ether_dhost[4] = MY_DEST_MAC4; + eh->ether_dhost[5] = MY_DEST_MAC5; + eh->ether_type = htons(ETH_P_IP); + tx_len += sizeof(struct ether_header); + + // Index of the network device + socket_address.sll_ifindex = if_idx.ifr_ifindex; + + // Address length + socket_address.sll_halen = ETH_ALEN; + + // Destination MAC + socket_address.sll_addr[0] = MY_DEST_MAC0; + socket_address.sll_addr[1] = MY_DEST_MAC1; + socket_address.sll_addr[2] = MY_DEST_MAC2; + socket_address.sll_addr[3] = MY_DEST_MAC3; + socket_address.sll_addr[4] = MY_DEST_MAC4; + socket_address.sll_addr[5] = MY_DEST_MAC5; + + // start timing + gettimeofday(&t_start, NULL); + read(fd, sendbuf + tx_len, sendsize - tx_len); + + // start to send + while (total_bytes_sent < bytes2send) + { + if ((bytes2send - total_bytes_sent) < quota) + { + quota = bytes2send - total_bytes_sent; + } + // send in slots + while (sentInSlot < quota) + { + // printf( + // "before: total_bytes_sent %d, sentInSlot %d, quota - sentInSlot %d\n", + // total_bytes_sent, sentInSlot, quota - sentInSlot); + read( + fd, sendbuf + tx_len, + ( + ((quota - sentInSlot) < (sendsize - tx_len)) ? + (quota - sentInSlot) : (sendsize - tx_len)) + ); + ret = sendto( + sockfd, sendbuf, + (quota - sentInSlot < sendsize) ? (quota - sentInSlot) : sendsize, + MSG_DONTWAIT, (struct sockaddr*)&socket_address, sizeof(struct sockaddr_ll)); + + if (ret <= 0) + { + fprintf(stderr, "! Fail to send: ret:%d, err:%d; wait for 100us..\n", ret, errno); + usleep(100); + continue; + } + total_bytes_sent += ret; + sentInSlot += ret; + // printf( + // "after: total_bytes_sent %d, sentInSlot %d, quota - sentInSlot %d\n", + // total_bytes_sent, sentInSlot, quota - sentInSlot); + } + // control bandwidth + if (total_bytes_sent < bytes2send) + { + gettimeofday(&t_now, NULL); + elapsedTime = (t_now.tv_sec - t_start.tv_sec) * 1000000.0 + (t_now.tv_usec - t_start.tv_usec); + if (elapsedTime < (slotLength * slot)) + { + // printf( + // "sent %d, quota %d, bytes2send %d, usleep %lfus\n", + // total_bytes_sent, quota, bytes2send, slotLength * slot - elapsedTime); + usleep((int)(slotLength * slot - elapsedTime)); + } + } + sentInSlot = 0; + ++slot; + } + + // 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_sent, elapsedTime, total_bytes_sent * 8 / elapsedTime); + + close(sockfd); + close(fd); + + return 0; +} diff --git a/offloading_binaries/c2s_bypassl3/main.o b/offloading_binaries/c2s_bypassl3/main.o new file mode 100644 index 0000000..5d21121 Binary files /dev/null and b/offloading_binaries/c2s_bypassl3/main.o differ diff --git a/offloading_binaries/c2s_normaltcp/c2s_normaltcp b/offloading_binaries/c2s_normaltcp/c2s_normaltcp index e0068d5..c56ec8f 100755 Binary files a/offloading_binaries/c2s_normaltcp/c2s_normaltcp and b/offloading_binaries/c2s_normaltcp/c2s_normaltcp differ diff --git a/offloading_binaries/c2s_normaltcp/main.c b/offloading_binaries/c2s_normaltcp/main.c index 29dedb4..049073a 100644 --- a/offloading_binaries/c2s_normaltcp/main.c +++ b/offloading_binaries/c2s_normaltcp/main.c @@ -32,7 +32,7 @@ // #define MY_DEST_MAC5 0x64 // #define DEFAULT_IF "wlan0" -#define BUF_SIZ 8192 +#define BUF_SIZ 65536 char isNumber(char number[]) { @@ -62,22 +62,21 @@ int main(int argc, char *argv[]) struct timeval t_start, t_end, t_now; // for socket int fd; // file descriptor of file to send - int sockfd; // socket - // int sendsize = 1488; - // char ifName[IFNAMSIZ]; + int sockfd; // socket char sendbuf[BUF_SIZ]; struct sockaddr_in servaddr; - struct ether_header *eh = (struct ether_header *) sendbuf; - struct iphdr *iph = (struct iphdr *) (sendbuf + sizeof(struct ether_header)); + // struct ether_header *eh = (struct ether_header *) sendbuf; + // struct iphdr *iph = (struct iphdr *) (sendbuf + sizeof(struct ether_header)); // struct sockaddr_ll socket_address; // for misc - int i, j, ret; + int ret; + int sendsize = 1460; // 1500 MTU - 20 IPv4 - 20 TCP int bytes2send = 0; struct stat st; if (argc < 4) { - printf("Usage: %s <[optional] bandwidth (bps)>\n", argv[0]); + printf("Usage: %s <[optional] bandwidth (bps)> <[optional] sendsize (bytes)>\n", argv[0]); exit(0); } @@ -85,6 +84,10 @@ int main(int argc, char *argv[]) if (argc > 4) quota = atoi(argv[4]) / 8 / (1000000 / slotLength); + // set sendsize (if larger than 1460 will do packetization (fragmentation)) + if (argc > 5) + sendsize = atoi(argv[5]); + // get file size (bytes2send) if (isNumber(argv[1])) { @@ -142,8 +145,10 @@ int main(int argc, char *argv[]) // printf( // "before: total_bytes_sent %d, sentInSlot %d, quota - sentInSlot %d\n", // total_bytes_sent, sentInSlot, quota - sentInSlot); - read(fd, sendbuf, (quota - sentInSlot < 4096) ? (quota - sentInSlot) : 4096); - ret = send(sockfd, sendbuf, (quota - sentInSlot < 4096) ? (quota - sentInSlot) : 4096, 0); + read(fd, sendbuf, (quota - sentInSlot < sendsize) ? (quota - sentInSlot) : sendsize); + ret = send( + sockfd, sendbuf, + (quota - sentInSlot < sendsize) ? (quota - sentInSlot) : sendsize, 0); if (ret <= 0) { @@ -158,14 +163,17 @@ int main(int argc, char *argv[]) // total_bytes_sent, sentInSlot, quota - sentInSlot); } // control bandwidth - gettimeofday(&t_now, NULL); - elapsedTime = (t_now.tv_sec - t_start.tv_sec) * 1000000.0 + (t_now.tv_usec - t_start.tv_usec); - if (elapsedTime < slotLength * slot) + if (total_bytes_sent < bytes2send) { - // printf( - // "sent %d, quota %d, bytes2send %d, usleep %lfus\n", - // total_bytes_sent, quota, bytes2send, slotLength * slot - elapsedTime); - usleep((int)(slotLength * slot - elapsedTime)); + gettimeofday(&t_now, NULL); + elapsedTime = (t_now.tv_sec - t_start.tv_sec) * 1000000.0 + (t_now.tv_usec - t_start.tv_usec); + if (elapsedTime < slotLength * slot) + { + // printf( + // "sent %d, quota %d, bytes2send %d, usleep %lfus\n", + // total_bytes_sent, quota, bytes2send, slotLength * slot - elapsedTime); + usleep((int)(slotLength * slot - elapsedTime)); + } } sentInSlot = 0; ++slot; @@ -174,7 +182,9 @@ int main(int argc, char *argv[]) // 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("duration(s):%lf\nthroughput(bps):%lf\n", elapsedTime, total_bytes_sent * 8 / elapsedTime); + printf( + "sent(bytes):%d\nduration(s):%lf\nthroughput(bps):%lf\n", + total_bytes_sent, elapsedTime, total_bytes_sent * 8 / elapsedTime); close(sockfd); close(fd); diff --git a/offloading_binaries/c2s_normaltcp/main.o b/offloading_binaries/c2s_normaltcp/main.o index ccd67fa..1360fc8 100644 Binary files a/offloading_binaries/c2s_normaltcp/main.o and b/offloading_binaries/c2s_normaltcp/main.o differ diff --git a/offloading_binaries/c2s_normaltcp_sendfile/c2s_normaltcp_sendfile b/offloading_binaries/c2s_normaltcp_sendfile/c2s_normaltcp_sendfile index de07062..fa25959 100755 Binary files a/offloading_binaries/c2s_normaltcp_sendfile/c2s_normaltcp_sendfile and b/offloading_binaries/c2s_normaltcp_sendfile/c2s_normaltcp_sendfile differ diff --git a/offloading_binaries/c2s_normaltcp_sendfile/main.c b/offloading_binaries/c2s_normaltcp_sendfile/main.c index 9c45d8f..c3bc334 100644 --- a/offloading_binaries/c2s_normaltcp_sendfile/main.c +++ b/offloading_binaries/c2s_normaltcp_sendfile/main.c @@ -69,13 +69,11 @@ int main(int argc, char *argv[]) struct timeval t_start, t_end, t_now; // for socket int fd; // file descriptor of file to send - int sockfd; // socket - // int sendsize = 1488; - // char ifName[IFNAMSIZ]; + int sockfd; // socket struct sockaddr_in servaddr; // struct sockaddr_ll socket_address; // for misc - int i, j, ret; + int ret; int bytes2send = 0; struct stat st; @@ -159,14 +157,17 @@ int main(int argc, char *argv[]) // total_bytes_sent, sentInSlot, quota - sentInSlot); } // control bandwidth - gettimeofday(&t_now, NULL); - elapsedTime = (t_now.tv_sec - t_start.tv_sec) * 1000000.0 + (t_now.tv_usec - t_start.tv_usec); - if (elapsedTime < slotLength * slot) + if (total_bytes_sent < bytes2send) { - // printf( - // "sent %d, quota %d, bytes2send %d, usleep %lfus\n", - // total_bytes_sent, quota, bytes2send, slotLength * slot - elapsedTime); - usleep((int)(slotLength * slot - elapsedTime)); + gettimeofday(&t_now, NULL); + elapsedTime = (t_now.tv_sec - t_start.tv_sec) * 1000000.0 + (t_now.tv_usec - t_start.tv_usec); + if (elapsedTime < slotLength * slot) + { + // printf( + // "sent %d, quota %d, bytes2send %d, usleep %lfus\n", + // total_bytes_sent, quota, bytes2send, slotLength * slot - elapsedTime); + usleep((int)(slotLength * slot - elapsedTime)); + } } sentInSlot = 0; ++slot; diff --git a/offloading_binaries/c2s_normaltcp_sendfile/main.o b/offloading_binaries/c2s_normaltcp_sendfile/main.o index c0f57ed..ff4a4a2 100644 Binary files a/offloading_binaries/c2s_normaltcp_sendfile/main.o and b/offloading_binaries/c2s_normaltcp_sendfile/main.o differ diff --git a/offloading_binaries/BypassL3Binary/Makefile b/offloading_binaries/c2s_normaludp/Makefile similarity index 67% rename from offloading_binaries/BypassL3Binary/Makefile rename to offloading_binaries/c2s_normaludp/Makefile index 7b6c665..98edc26 100644 --- a/offloading_binaries/BypassL3Binary/Makefile +++ b/offloading_binaries/c2s_normaludp/Makefile @@ -1,7 +1,7 @@ CC = arm-linux-androideabi-gcc -#CC = gcc -CFLAGS = -pie -fPIE -lm -TARGET = bypassl3 +# CC = gcc +CFLAGS = -pie -fPIE +TARGET = c2s_normaludp OBJS = $(patsubst %.c, %.o, $(wildcard *.c)) HEADERS = $(wildcard *.h) @@ -15,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/Normal_lo/normal_lo b/offloading_binaries/c2s_normaludp/c2s_normaludp similarity index 53% rename from offloading_binaries/Normal_lo/normal_lo rename to offloading_binaries/c2s_normaludp/c2s_normaludp index 01c850f..907ed0a 100755 Binary files a/offloading_binaries/Normal_lo/normal_lo and b/offloading_binaries/c2s_normaludp/c2s_normaludp differ diff --git a/offloading_binaries/c2s_normaludp/main.c b/offloading_binaries/c2s_normaludp/main.c new file mode 100644 index 0000000..7b0afef --- /dev/null +++ b/offloading_binaries/c2s_normaludp/main.c @@ -0,0 +1,195 @@ +/* + * Initial commit by Yibo @ Jul. 28, 2015 + * Last update by Yanzi @ Sept. 26, 2016 + */ + +#include +#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 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 65536 + +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[]) +{ + // for bandwidth control + uint slotLength = 10000; // in microseconds, for bandwidth control + uint quota = 1000000000; // default bytes per slot, default 1GB/slot + uint sentInSlot = 0, slot = 1; + uint total_bytes_sent = 0; + // 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 ifName[IFNAMSIZ]; + char sendbuf[BUF_SIZ]; + struct sockaddr_in servaddr; + // struct ether_header *eh = (struct ether_header *) sendbuf; + // struct iphdr *iph = (struct iphdr *) (sendbuf + sizeof(struct ether_header)); + // struct sockaddr_ll socket_address; + // for misc + int ret; + int sendsize = 1472; // 1500 MTU - 20 IPv4 - 8 UDP + int bytes2send = 0; + struct stat st; + + if (argc < 4) + { + printf("Usage: %s <[optional] bandwidth (bps)> <[optional] sendsize (bytes)>\n", argv[0]); + exit(0); + } + + // set bandwidth + if (argc > 4) + quota = atoi(argv[4]) / 8 / (1000000 / slotLength); + + // set sendsize (if larger than 1472 will do packetization (fragmentation) (is this true??)) + if (argc > 5) + sendsize = atoi(argv[5]); + + // get file size (bytes2send) + if (isNumber(argv[1])) + { + // set bytes to send + bytes2send = atoi(argv[1]); + // open file descriptor + fd = open("/data/local/tmp/bigfile", O_RDONLY); + if (fd == -1) + { + fprintf(stderr, "! Unable to open /data/local/tmp/bigfile.\n"); + exit(1); + } + } + else + { + // open file descriptor + fd = open(argv[1], O_RDONLY); + if (fd == -1) + { + fprintf(stderr, "! Unable to open file %s.\n", argv[1]); + exit(1); + } + fstat(fd, &st); + bytes2send = st.st_size; + printf("bytes2send:%d\n", bytes2send); + } + + // bind socket + sockfd = socket(AF_INET, SOCK_DGRAM, 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); + } + + // start timing + gettimeofday(&t_start, NULL); + + // start to send + while (total_bytes_sent < bytes2send) + { + if ((bytes2send - total_bytes_sent) < quota) + { + quota = bytes2send - total_bytes_sent; + } + // send in slots + while (sentInSlot < quota) + { + // printf( + // "before: total_bytes_sent %d, sentInSlot %d, quota - sentInSlot %d\n", + // total_bytes_sent, sentInSlot, quota - sentInSlot); + read(fd, sendbuf, (quota - sentInSlot < sendsize) ? (quota - sentInSlot) : sendsize); + ret = sendto( + sockfd, sendbuf, + (quota - sentInSlot < sendsize) ? (quota - sentInSlot) : sendsize, + 0, (struct sockaddr *)&servaddr, sizeof(servaddr)); + if (ret <= 0) + { + fprintf(stderr, "! Fail to send: ret:%d, err:%d; wait for 100us..\n", ret, errno); + usleep(100); + continue; + } + total_bytes_sent += ret; + sentInSlot += ret; + // printf( + // "after: total_bytes_sent %d, sentInSlot %d, quota - sentInSlot %d\n", + // total_bytes_sent, sentInSlot, quota - sentInSlot); + } + // control bandwidth + if (total_bytes_sent < bytes2send) + { + gettimeofday(&t_now, NULL); + elapsedTime = (t_now.tv_sec - t_start.tv_sec) * 1000000.0 + (t_now.tv_usec - t_start.tv_usec); + if (elapsedTime < slotLength * slot) + { + // printf( + // "sent %d, quota %d, bytes2send %d, usleep %lfus\n", + // total_bytes_sent, quota, bytes2send, slotLength * slot - elapsedTime); + usleep((int)(slotLength * slot - elapsedTime)); + } + } + sentInSlot = 0; + ++slot; + } + + // 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_sent, elapsedTime, total_bytes_sent * 8 / elapsedTime); + + close(sockfd); + close(fd); + + return 0; +} diff --git a/offloading_binaries/c2s_normaludp/main.o b/offloading_binaries/c2s_normaludp/main.o new file mode 100644 index 0000000..8d1919e Binary files /dev/null and b/offloading_binaries/c2s_normaludp/main.o differ diff --git a/offloading_binaries/Normal_udp/Makefile b/offloading_binaries/c2s_readfile_only/Makefile similarity index 66% rename from offloading_binaries/Normal_udp/Makefile rename to offloading_binaries/c2s_readfile_only/Makefile index 3bdff0a..26289cd 100644 --- a/offloading_binaries/Normal_udp/Makefile +++ b/offloading_binaries/c2s_readfile_only/Makefile @@ -1,7 +1,7 @@ CC = arm-linux-androideabi-gcc -#CC = gcc -CFLAGS = -pie -fPIE -lm -TARGET = normal_udp +# CC = gcc +CFLAGS = -pie -fPIE +TARGET = c2s_readfile_only OBJS = $(patsubst %.c, %.o, $(wildcard *.c)) HEADERS = $(wildcard *.h) @@ -15,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/Normal_udp_usb/normal_udp_usb b/offloading_binaries/c2s_readfile_only/c2s_readfile_only similarity index 55% rename from offloading_binaries/Normal_udp_usb/normal_udp_usb rename to offloading_binaries/c2s_readfile_only/c2s_readfile_only index 1a060cd..6173a6a 100755 Binary files a/offloading_binaries/Normal_udp_usb/normal_udp_usb and b/offloading_binaries/c2s_readfile_only/c2s_readfile_only differ diff --git a/offloading_binaries/c2s_readfile_only/main.c b/offloading_binaries/c2s_readfile_only/main.c new file mode 100644 index 0000000..17b7352 --- /dev/null +++ b/offloading_binaries/c2s_readfile_only/main.c @@ -0,0 +1,165 @@ +/* + * Initial commit by Yibo @ Jul. 28, 2015 + * Last update by Yanzi @ Sept. 26, 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 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 4096 + +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 slotLength = 10000; // in microseconds, for bandwidth control + uint quota = 1000000000; // default bytes per slot, default 1GB/slot + uint sentInSlot = 0, slot = 1; + uint total_bytes_sent = 0; + // 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 + // int sendsize = 1488; + // char ifName[IFNAMSIZ]; + char sendbuf[BUF_SIZ]; + struct sockaddr_in servaddr; + struct ether_header *eh = (struct ether_header *) sendbuf; + struct iphdr *iph = (struct iphdr *) (sendbuf + sizeof(struct ether_header)); + // struct sockaddr_ll socket_address; + // for misc + int ret; + int bytes2send = 0; + struct stat st; + + if (argc < 2) + { + printf("Usage: %s <[optional] bandwidth (bps)>\n", argv[0]); + exit(0); + } + + // set bandwidth + if (argc > 2) + quota = atoi(argv[2]) / 8 / (1000000 / slotLength); + + // get file size (bytes2send) + if (isNumber(argv[1])) + { + // set bytes to send + bytes2send = atoi(argv[1]); + // open file descriptor + fd = open("/data/local/tmp/bigfile", O_RDONLY); + if (fd == -1) + { + fprintf(stderr, "! Unable to open /data/local/tmp/bigfile.\n"); + exit(1); + } + } + else + { + // open file descriptor + fd = open(argv[1], O_RDONLY); + if (fd == -1) + { + fprintf(stderr, "! Unable to open file %s.\n", argv[1]); + exit(1); + } + fstat(fd, &st); + bytes2send = st.st_size; + printf("bytes2send:%d\n", bytes2send); + } + + // start timing + gettimeofday(&t_start, NULL); + + // start to send + while (total_bytes_sent < bytes2send) + { + if ((bytes2send - total_bytes_sent) < quota) + { + quota = bytes2send - total_bytes_sent; + } + // send in slots + while (sentInSlot < quota) + { + // printf( + // "before: total_bytes_sent %d, sentInSlot %d, quota - sentInSlot %d\n", + // total_bytes_sent, sentInSlot, quota - sentInSlot); + read(fd, sendbuf, (quota - sentInSlot < BUF_SIZ) ? (quota - sentInSlot) : BUF_SIZ); + + ret = (quota - sentInSlot < BUF_SIZ) ? (quota - sentInSlot) : BUF_SIZ; + total_bytes_sent += ret; + sentInSlot += ret; + // printf( + // "after: total_bytes_sent %d, sentInSlot %d, quota - sentInSlot %d\n", + // total_bytes_sent, sentInSlot, quota - sentInSlot); + } + // control bandwidth + if (total_bytes_sent < bytes2send) + { + gettimeofday(&t_now, NULL); + elapsedTime = (t_now.tv_sec - t_start.tv_sec) * 1000000.0 + (t_now.tv_usec - t_start.tv_usec); + if (elapsedTime < slotLength * slot) + { + // printf( + // "sent %d, quota %d, bytes2send %d, usleep %lfus\n", + // total_bytes_sent, quota, bytes2send, slotLength * slot - elapsedTime); + usleep((int)(slotLength * slot - elapsedTime)); + } + } + sentInSlot = 0; + ++slot; + } + + // 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("duration(s):%lf\nthroughput(bps):%lf\n", elapsedTime, total_bytes_sent * 8 / elapsedTime); + + close(fd); + + return 0; +} diff --git a/offloading_binaries/c2s_readfile_only/main.o b/offloading_binaries/c2s_readfile_only/main.o new file mode 100644 index 0000000..0a0e5d4 Binary files /dev/null and b/offloading_binaries/c2s_readfile_only/main.o differ