diff --git a/OffloadingDemo/.idea/misc.xml b/OffloadingDemo/.idea/misc.xml index 95f0f03..1caa136 100755 --- a/OffloadingDemo/.idea/misc.xml +++ b/OffloadingDemo/.idea/misc.xml @@ -37,7 +37,7 @@ - + diff --git a/OffloadingDemo/mobile/mobile.iml b/OffloadingDemo/mobile/mobile.iml index bd78d65..ece0ef9 100755 --- a/OffloadingDemo/mobile/mobile.iml +++ b/OffloadingDemo/mobile/mobile.iml @@ -82,7 +82,6 @@ - diff --git a/OffloadingDemo/wear/wear.iml b/OffloadingDemo/wear/wear.iml index 37ff89b..57a96cb 100755 --- a/OffloadingDemo/wear/wear.iml +++ b/OffloadingDemo/wear/wear.iml @@ -94,7 +94,6 @@ - diff --git a/offloading_binaries/BypassL3Binary/Makefile b/offloading_binaries/BypassL3Binary/Makefile new file mode 100644 index 0000000..7b6c665 --- /dev/null +++ b/offloading_binaries/BypassL3Binary/Makefile @@ -0,0 +1,21 @@ +CC = arm-linux-androideabi-gcc +#CC = gcc +CFLAGS = -pie -fPIE -lm +TARGET = bypassl3 + +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/BypassL3Binary/bypassl3 b/offloading_binaries/BypassL3Binary/bypassl3 new file mode 100755 index 0000000..5189a90 Binary files /dev/null and b/offloading_binaries/BypassL3Binary/bypassl3 differ diff --git a/offloading_binaries/BypassL3Binary/main.c b/offloading_binaries/BypassL3Binary/main.c new file mode 100644 index 0000000..fba88fe --- /dev/null +++ b/offloading_binaries/BypassL3Binary/main.c @@ -0,0 +1,206 @@ +/* + * 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/BypassL3_lo/Makefile b/offloading_binaries/BypassL3_lo/Makefile new file mode 100644 index 0000000..8937390 --- /dev/null +++ b/offloading_binaries/BypassL3_lo/Makefile @@ -0,0 +1,21 @@ +CC = arm-linux-androideabi-gcc +#CC = gcc +CFLAGS = -pie -fPIE -lm +TARGET = bypassl3_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/BypassL3_lo/bypassl3_lo b/offloading_binaries/BypassL3_lo/bypassl3_lo new file mode 100755 index 0000000..5189a90 Binary files /dev/null and b/offloading_binaries/BypassL3_lo/bypassl3_lo differ diff --git a/offloading_binaries/BypassL3_lo/main.c b/offloading_binaries/BypassL3_lo/main.c new file mode 100644 index 0000000..fba88fe --- /dev/null +++ b/offloading_binaries/BypassL3_lo/main.c @@ -0,0 +1,206 @@ +/* + * 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/BypassL3_lo/main.o b/offloading_binaries/BypassL3_lo/main.o new file mode 100644 index 0000000..b92680c Binary files /dev/null and b/offloading_binaries/BypassL3_lo/main.o differ diff --git a/offloading_binaries/BypassL3_recv/Makefile b/offloading_binaries/BypassL3_recv/Makefile new file mode 100644 index 0000000..e1bce73 --- /dev/null +++ b/offloading_binaries/BypassL3_recv/Makefile @@ -0,0 +1,20 @@ +CC = arm-linux-androideabi-gcc +CFLAGS = -pie -fPIE +TARGET = bypassl3_recv + +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/BypassL3_recv/bypassl3_recv b/offloading_binaries/BypassL3_recv/bypassl3_recv new file mode 100755 index 0000000..2c01307 Binary files /dev/null and b/offloading_binaries/BypassL3_recv/bypassl3_recv differ diff --git a/offloading_binaries/BypassL3_recv/main.c b/offloading_binaries/BypassL3_recv/main.c new file mode 100644 index 0000000..ebbc6e7 --- /dev/null +++ b/offloading_binaries/BypassL3_recv/main.c @@ -0,0 +1,125 @@ +/* + * 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 new file mode 100644 index 0000000..b19ea68 Binary files /dev/null and b/offloading_binaries/BypassL3_recv/main.o differ diff --git a/offloading_binaries/BypassL3_recv_lo/Makefile b/offloading_binaries/BypassL3_recv_lo/Makefile new file mode 100644 index 0000000..a5e7006 --- /dev/null +++ b/offloading_binaries/BypassL3_recv_lo/Makefile @@ -0,0 +1,20 @@ +CC = arm-linux-androideabi-gcc +CFLAGS = -pie -fPIE +TARGET = bypassl3_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/BypassL3_recv_lo/bypassl3_recv_lo b/offloading_binaries/BypassL3_recv_lo/bypassl3_recv_lo new file mode 100755 index 0000000..7a17840 Binary files /dev/null and b/offloading_binaries/BypassL3_recv_lo/bypassl3_recv_lo differ diff --git a/offloading_binaries/BypassL3_recv_lo/main.c b/offloading_binaries/BypassL3_recv_lo/main.c new file mode 100644 index 0000000..4c1bc87 --- /dev/null +++ b/offloading_binaries/BypassL3_recv_lo/main.c @@ -0,0 +1,125 @@ +/* + * 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("192.168.1.15"); + 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_lo/main.o b/offloading_binaries/BypassL3_recv_lo/main.o new file mode 100644 index 0000000..0c85b10 Binary files /dev/null and b/offloading_binaries/BypassL3_recv_lo/main.o differ diff --git a/offloading_binaries/BypassL3_usb/Makefile b/offloading_binaries/BypassL3_usb/Makefile new file mode 100644 index 0000000..34e1833 --- /dev/null +++ b/offloading_binaries/BypassL3_usb/Makefile @@ -0,0 +1,21 @@ +CC = arm-linux-androideabi-gcc +#CC = gcc +CFLAGS = -pie -fPIE -lm +TARGET = bypassl3_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/BypassL3_usb/bypassl3_usb b/offloading_binaries/BypassL3_usb/bypassl3_usb new file mode 100755 index 0000000..139a0ae Binary files /dev/null and b/offloading_binaries/BypassL3_usb/bypassl3_usb differ diff --git a/offloading_binaries/BypassL3_usb/main.c b/offloading_binaries/BypassL3_usb/main.c new file mode 100644 index 0000000..77fefdd --- /dev/null +++ b/offloading_binaries/BypassL3_usb/main.c @@ -0,0 +1,206 @@ +/* + * 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 "usb0" +//#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/BypassL3_usb/main.o b/offloading_binaries/BypassL3_usb/main.o new file mode 100644 index 0000000..c305dbb Binary files /dev/null and b/offloading_binaries/BypassL3_usb/main.o differ diff --git a/offloading_binaries/Normal/Makefile b/offloading_binaries/Normal/Makefile new file mode 100644 index 0000000..a99fb5f --- /dev/null +++ b/offloading_binaries/Normal/Makefile @@ -0,0 +1,23 @@ +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 + +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/main.c b/offloading_binaries/Normal/main.c new file mode 100644 index 0000000..537e790 --- /dev/null +++ b/offloading_binaries/Normal/main.c @@ -0,0 +1,126 @@ +/* + * Initial commit by Yibo @ Jul. 28, 2015 + * Last update by Yanzi @ Sept. 23, 2016 + */ + +#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; + + 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; + + 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("10.0.0.169"); + 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/main.o b/offloading_binaries/Normal/main.o new file mode 100644 index 0000000..62833f1 Binary files /dev/null and b/offloading_binaries/Normal/main.o differ diff --git a/offloading_binaries/Normal/normal b/offloading_binaries/Normal/normal new file mode 100755 index 0000000..7da3ec2 Binary files /dev/null and b/offloading_binaries/Normal/normal differ diff --git a/offloading_binaries/Normal_donothing/Makefile b/offloading_binaries/Normal_donothing/Makefile new file mode 100644 index 0000000..a15cbec --- /dev/null +++ b/offloading_binaries/Normal_donothing/Makefile @@ -0,0 +1,21 @@ +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 new file mode 100644 index 0000000..2b8bc44 --- /dev/null +++ b/offloading_binaries/Normal_donothing/main.c @@ -0,0 +1,130 @@ +/* + * 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 new file mode 100755 index 0000000..6052a63 Binary files /dev/null and b/offloading_binaries/Normal_donothing/normal_readonly differ diff --git a/offloading_binaries/Normal_lo/Makefile b/offloading_binaries/Normal_lo/Makefile new file mode 100644 index 0000000..e92bc6b --- /dev/null +++ b/offloading_binaries/Normal_lo/Makefile @@ -0,0 +1,23 @@ +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 new file mode 100644 index 0000000..de3d00f --- /dev/null +++ b/offloading_binaries/Normal_lo/main.c @@ -0,0 +1,131 @@ +/* + * 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 new file mode 100644 index 0000000..53f3881 Binary files /dev/null and b/offloading_binaries/Normal_lo/main.o differ diff --git a/offloading_binaries/Normal_lo/normal_lo b/offloading_binaries/Normal_lo/normal_lo new file mode 100755 index 0000000..01c850f Binary files /dev/null and b/offloading_binaries/Normal_lo/normal_lo differ diff --git a/offloading_binaries/Normal_memory/Makefile b/offloading_binaries/Normal_memory/Makefile new file mode 100644 index 0000000..792847a --- /dev/null +++ b/offloading_binaries/Normal_memory/Makefile @@ -0,0 +1,20 @@ +CC = arm-linux-androideabi-gcc +CFLAGS = -pie -fPIE +TARGET = normal_memory + +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_memory/main.c b/offloading_binaries/Normal_memory/main.c new file mode 100644 index 0000000..e30688b --- /dev/null +++ b/offloading_binaries/Normal_memory/main.c @@ -0,0 +1,100 @@ +/* + * 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 new file mode 100755 index 0000000..259244d Binary files /dev/null and b/offloading_binaries/Normal_memory/normal_memory differ diff --git a/offloading_binaries/Normal_recv/Makefile b/offloading_binaries/Normal_recv/Makefile new file mode 100644 index 0000000..42e30bf --- /dev/null +++ b/offloading_binaries/Normal_recv/Makefile @@ -0,0 +1,20 @@ +CC = arm-linux-androideabi-gcc +CFLAGS = -pie -fPIE +TARGET = normal_recv + +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_recv/main.c b/offloading_binaries/Normal_recv/main.c new file mode 100644 index 0000000..535d67e --- /dev/null +++ b/offloading_binaries/Normal_recv/main.c @@ -0,0 +1,102 @@ +/* + * 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[]) +{ + 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, sendsize=1488, packet_num, offset = 0, port = 4445; + int fd; /* file descriptor for file to send */ + struct timeval t_start,t_end; + + struct sockaddr_in servaddr,cliaddr; + + 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(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); + } + + 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 = recv(sockfd, sendbuf, 4096, 0); + if (ret <= 0) + { + printf("recv fail\n"); + usleep(100); + continue; + } + write(fd, sendbuf, ret); + 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_recv/normal_recv b/offloading_binaries/Normal_recv/normal_recv new file mode 100755 index 0000000..2193f5f Binary files /dev/null and b/offloading_binaries/Normal_recv/normal_recv differ diff --git a/offloading_binaries/Normal_recv_lo/Makefile b/offloading_binaries/Normal_recv_lo/Makefile new file mode 100644 index 0000000..939332d --- /dev/null +++ b/offloading_binaries/Normal_recv_lo/Makefile @@ -0,0 +1,20 @@ +CC = arm-linux-androideabi-gcc +CFLAGS = -pie -fPIE +TARGET = normal_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/Normal_recv_lo/main.c b/offloading_binaries/Normal_recv_lo/main.c new file mode 100644 index 0000000..945d914 --- /dev/null +++ b/offloading_binaries/Normal_recv_lo/main.c @@ -0,0 +1,102 @@ +/* + * 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[]) +{ + 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, sendsize=1488, packet_num, offset = 0, port = 4445; + int fd; /* file descriptor for file to send */ + struct timeval t_start,t_end; + + struct sockaddr_in servaddr,cliaddr; + + 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("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); + } + + 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 = recv(sockfd, sendbuf, 4096, 0); + if (ret <= 0) + { + printf("recv fail\n"); + usleep(100); + continue; + } + write(fd, sendbuf, ret); + 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_recv_lo/main.o b/offloading_binaries/Normal_recv_lo/main.o new file mode 100644 index 0000000..b4afb87 Binary files /dev/null and b/offloading_binaries/Normal_recv_lo/main.o differ diff --git a/offloading_binaries/Normal_recv_lo/normal_recv_lo b/offloading_binaries/Normal_recv_lo/normal_recv_lo new file mode 100755 index 0000000..514b9c1 Binary files /dev/null and b/offloading_binaries/Normal_recv_lo/normal_recv_lo differ diff --git a/offloading_binaries/Normal_udp/Makefile b/offloading_binaries/Normal_udp/Makefile new file mode 100644 index 0000000..3bdff0a --- /dev/null +++ b/offloading_binaries/Normal_udp/Makefile @@ -0,0 +1,21 @@ +CC = arm-linux-androideabi-gcc +#CC = gcc +CFLAGS = -pie -fPIE -lm +TARGET = normal_udp + +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/main.c b/offloading_binaries/Normal_udp/main.c new file mode 100644 index 0000000..e226700 --- /dev/null +++ b/offloading_binaries/Normal_udp/main.c @@ -0,0 +1,123 @@ +/* + * 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 new file mode 100644 index 0000000..cefe867 Binary files /dev/null and b/offloading_binaries/Normal_udp/main.o differ diff --git a/offloading_binaries/Normal_udp/normal_udp b/offloading_binaries/Normal_udp/normal_udp new file mode 100755 index 0000000..efdea1a Binary files /dev/null and b/offloading_binaries/Normal_udp/normal_udp differ diff --git a/offloading_binaries/Normal_udp_lo/Makefile b/offloading_binaries/Normal_udp_lo/Makefile new file mode 100644 index 0000000..5c13655 --- /dev/null +++ b/offloading_binaries/Normal_udp_lo/Makefile @@ -0,0 +1,21 @@ +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 new file mode 100644 index 0000000..ab72016 --- /dev/null +++ b/offloading_binaries/Normal_udp_lo/main.c @@ -0,0 +1,124 @@ +/* + * 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 new file mode 100644 index 0000000..297265b Binary files /dev/null and b/offloading_binaries/Normal_udp_lo/main.o differ diff --git a/offloading_binaries/Normal_udp_lo/normal_udp_lo b/offloading_binaries/Normal_udp_lo/normal_udp_lo new file mode 100755 index 0000000..8475673 Binary files /dev/null and b/offloading_binaries/Normal_udp_lo/normal_udp_lo differ diff --git a/offloading_binaries/Normal_udp_recv/Makefile b/offloading_binaries/Normal_udp_recv/Makefile new file mode 100644 index 0000000..34bb5e8 --- /dev/null +++ b/offloading_binaries/Normal_udp_recv/Makefile @@ -0,0 +1,21 @@ +#CC = gcc +CC = arm-linux-androideabi-gcc +CFLAGS = -pie -fPIE +TARGET = normal_udp_recv + +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_recv/main.c b/offloading_binaries/Normal_udp_recv/main.c new file mode 100644 index 0000000..898a192 --- /dev/null +++ b/offloading_binaries/Normal_udp_recv/main.c @@ -0,0 +1,111 @@ +/* + * 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 + +#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, sendsize=1458, packet_num, offset = 0, port = 32000; + int fd; /* file descriptor for file to send */ + struct timeval t_start,t_end; + + struct sockaddr_in servaddr,cliaddr; +//printf("init"); + 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_DGRAM, 0); +//printf("sockfd"); + 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); +//printf("servaddr"); +// bind(sockfd, (struct sockaddr *)&servaddr,sizeof(servaddr)); + 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); + } + + gettimeofday(&t_start, NULL); +//printf("gettime"); + // if (bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) +// { +// fprintf(stderr, "unable to connect the server.\n"); +// exit(1); +// } +// printf("bind"); + sendto(sockfd, "0\n",strlen("0\n"),0, (struct sockaddr *)&servaddr, sizeof(servaddr)); + + while (offset < packet_num) + { + // clilen= sizeof(cliaddr); + ret = recvfrom(sockfd, sendbuf, sendsize, 0, NULL, NULL); +// printf("%d\t%d\n", ret, errno); + if (ret <= 0) + { + printf("recv fail\n"); + usleep(100); + continue; + } + if (sendbuf[50] != '0') continue; + write(fd, sendbuf, ret); + offset += ret; +// printf("%d\n", offset); + } +// 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_recv/main.o b/offloading_binaries/Normal_udp_recv/main.o new file mode 100644 index 0000000..35d3a2e Binary files /dev/null and b/offloading_binaries/Normal_udp_recv/main.o differ diff --git a/offloading_binaries/Normal_udp_recv/normal_udp_recv b/offloading_binaries/Normal_udp_recv/normal_udp_recv new file mode 100755 index 0000000..9167568 Binary files /dev/null and b/offloading_binaries/Normal_udp_recv/normal_udp_recv differ diff --git a/offloading_binaries/Normal_udp_recv_lo/Makefile b/offloading_binaries/Normal_udp_recv_lo/Makefile new file mode 100644 index 0000000..b0aab9c --- /dev/null +++ b/offloading_binaries/Normal_udp_recv_lo/Makefile @@ -0,0 +1,21 @@ +#CC = gcc +CC = arm-linux-androideabi-gcc +CFLAGS = -pie -fPIE +TARGET = normal_udp_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/Normal_udp_recv_lo/main.c b/offloading_binaries/Normal_udp_recv_lo/main.c new file mode 100644 index 0000000..cb3805c --- /dev/null +++ b/offloading_binaries/Normal_udp_recv_lo/main.c @@ -0,0 +1,111 @@ +/* + * 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 + +#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, sendsize=1458, packet_num, offset = 0, port = 32000; + int fd; /* file descriptor for file to send */ + struct timeval t_start,t_end; + + struct sockaddr_in servaddr,cliaddr; +//printf("init"); + 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_DGRAM, 0); +//printf("sockfd"); + 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); +//printf("servaddr"); +// bind(sockfd, (struct sockaddr *)&servaddr,sizeof(servaddr)); + 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); + } + + gettimeofday(&t_start, NULL); +//printf("gettime"); + // if (bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) +// { +// fprintf(stderr, "unable to connect the server.\n"); +// exit(1); +// } +// printf("bind"); + sendto(sockfd, "0\n",strlen("0\n"),0, (struct sockaddr *)&servaddr, sizeof(servaddr)); + + while (offset < packet_num) + { + // clilen= sizeof(cliaddr); + ret = recvfrom(sockfd, sendbuf, sendsize, 0, NULL, NULL); +// printf("%d\t%d\n", ret, errno); + if (ret <= 0) + { + printf("recv fail\n"); + usleep(100); + continue; + } + if (sendbuf[50] != '0') continue; + write(fd, sendbuf, ret); + offset += ret; +// printf("%d\n", offset); + } +// 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_recv_lo/main.o b/offloading_binaries/Normal_udp_recv_lo/main.o new file mode 100644 index 0000000..3ad2ad5 Binary files /dev/null and b/offloading_binaries/Normal_udp_recv_lo/main.o differ diff --git a/offloading_binaries/Normal_udp_recv_lo/normal_udp_recv_lo b/offloading_binaries/Normal_udp_recv_lo/normal_udp_recv_lo new file mode 100755 index 0000000..1542a67 Binary files /dev/null and b/offloading_binaries/Normal_udp_recv_lo/normal_udp_recv_lo differ diff --git a/offloading_binaries/Normal_udp_usb/Makefile b/offloading_binaries/Normal_udp_usb/Makefile new file mode 100644 index 0000000..87d82c4 --- /dev/null +++ b/offloading_binaries/Normal_udp_usb/Makefile @@ -0,0 +1,21 @@ +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 new file mode 100644 index 0000000..d7bda03 --- /dev/null +++ b/offloading_binaries/Normal_udp_usb/main.c @@ -0,0 +1,124 @@ +/* + * 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 new file mode 100644 index 0000000..c07d53f Binary files /dev/null and b/offloading_binaries/Normal_udp_usb/main.o differ diff --git a/offloading_binaries/Normal_udp_usb/normal_udp_usb b/offloading_binaries/Normal_udp_usb/normal_udp_usb new file mode 100755 index 0000000..1a060cd Binary files /dev/null and b/offloading_binaries/Normal_udp_usb/normal_udp_usb differ diff --git a/offloading_binaries/Normal_usb/Makefile b/offloading_binaries/Normal_usb/Makefile new file mode 100644 index 0000000..b3b44aa --- /dev/null +++ b/offloading_binaries/Normal_usb/Makefile @@ -0,0 +1,23 @@ +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_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) + +#$(call import-module,android-ndk-profiler) diff --git a/offloading_binaries/Normal_usb/main.c b/offloading_binaries/Normal_usb/main.c new file mode 100644 index 0000000..dd709c2 --- /dev/null +++ b/offloading_binaries/Normal_usb/main.c @@ -0,0 +1,131 @@ +/* + * 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 "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; + + 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("10.42.0.1"); + 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_usb/main.o b/offloading_binaries/Normal_usb/main.o new file mode 100644 index 0000000..c7b9829 Binary files /dev/null and b/offloading_binaries/Normal_usb/main.o differ diff --git a/offloading_binaries/Normal_usb/normal_usb b/offloading_binaries/Normal_usb/normal_usb new file mode 100755 index 0000000..55edd04 Binary files /dev/null and b/offloading_binaries/Normal_usb/normal_usb differ diff --git a/offloading_binaries/Sendfile/Makefile b/offloading_binaries/Sendfile/Makefile new file mode 100644 index 0000000..9fa0981 --- /dev/null +++ b/offloading_binaries/Sendfile/Makefile @@ -0,0 +1,20 @@ +CC = arm-linux-androideabi-gcc +CFLAGS = -pie -fPIE +TARGET = sendfile + +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/Sendfile/main.c b/offloading_binaries/Sendfile/main.c new file mode 100644 index 0000000..8fb2710 --- /dev/null +++ b/offloading_binaries/Sendfile/main.c @@ -0,0 +1,127 @@ +/* + * 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[]) +{ + int slotLength = 10000; // in microseconds + int quota = 1000000000; // Bytes per slot, default 1GB/slot + int sentInSlot = 0, slot = 1; + double elapsedTime; + + int sockfd; + 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; + int outstanding; + + + struct sockaddr_in servaddr; + + 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) + { + ret = sendfile(sockfd, fd, (off_t *)&offset, quota - sentInSlot); + 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++; + + //ioctl(sockfd, SIOCOUTQ, &outstanding); + //if (outstanding > 0) + //{ + // continue; + //} + //ret = sendfile(sockfd, fd, (off_t *)&offset, 4096); + + } + 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/Sendfile/old.c_orig b/offloading_binaries/Sendfile/old.c_orig new file mode 100644 index 0000000..8875c21 --- /dev/null +++ b/offloading_binaries/Sendfile/old.c_orig @@ -0,0 +1,94 @@ +/* + * 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=4096, 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]); + else + packet_num = 166666*1488; + + 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); + + connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)); + + fd = open("bigfile"); + if (fd == -1) { + fprintf(stderr, "unable to open the file.\n"); + exit(1); + } + + gettimeofday(&t_start, NULL); + while (offset < packet_num) + { + ret = sendfile(sockfd, fd, (off_t *)&offset, sendsize); + if (ret <= 0) + { + printf("sendfile fail\n"); + usleep(100); + continue; + } + offset += sendsize; + } + gettimeofday(&t_end, NULL); + printf("time cost is: %lfms.\n", (t_end.tv_sec-t_start.tv_sec)*1000.0+(t_end.tv_usec-t_start.tv_usec)/1000.0); + + close(fd); + close(sockfd); + + return 0; +} diff --git a/offloading_binaries/Sendfile/sendfile b/offloading_binaries/Sendfile/sendfile new file mode 100755 index 0000000..2988ebf Binary files /dev/null and b/offloading_binaries/Sendfile/sendfile differ diff --git a/offloading_binaries/Sendfile_lo/Makefile b/offloading_binaries/Sendfile_lo/Makefile new file mode 100644 index 0000000..fcac9d2 --- /dev/null +++ b/offloading_binaries/Sendfile_lo/Makefile @@ -0,0 +1,20 @@ +CC = arm-linux-androideabi-gcc +CFLAGS = -pie -fPIE +TARGET = sendfile_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/Sendfile_lo/main.c b/offloading_binaries/Sendfile_lo/main.c new file mode 100644 index 0000000..a4f4859 --- /dev/null +++ b/offloading_binaries/Sendfile_lo/main.c @@ -0,0 +1,128 @@ +/* + * 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[]) +{ + int slotLength = 10000; // in microseconds + int quota = 1000000000; // Bytes per slot, default 1GB/slot + int sentInSlot = 0, slot = 1; + double elapsedTime; + + int sockfd; + 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; + int outstanding; + + + struct sockaddr_in servaddr; + + 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) + { + ret = sendfile(sockfd, fd, (off_t *)&offset, quota - sentInSlot); +// printf("err: %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++; + + //ioctl(sockfd, SIOCOUTQ, &outstanding); + //if (outstanding > 0) + //{ + // continue; + //} + //ret = sendfile(sockfd, fd, (off_t *)&offset, 4096); + + } + 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/Sendfile_lo/main.o b/offloading_binaries/Sendfile_lo/main.o new file mode 100644 index 0000000..d9e60bd Binary files /dev/null and b/offloading_binaries/Sendfile_lo/main.o differ diff --git a/offloading_binaries/Sendfile_lo/old.c_orig b/offloading_binaries/Sendfile_lo/old.c_orig new file mode 100644 index 0000000..8875c21 --- /dev/null +++ b/offloading_binaries/Sendfile_lo/old.c_orig @@ -0,0 +1,94 @@ +/* + * 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=4096, 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]); + else + packet_num = 166666*1488; + + 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); + + connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)); + + fd = open("bigfile"); + if (fd == -1) { + fprintf(stderr, "unable to open the file.\n"); + exit(1); + } + + gettimeofday(&t_start, NULL); + while (offset < packet_num) + { + ret = sendfile(sockfd, fd, (off_t *)&offset, sendsize); + if (ret <= 0) + { + printf("sendfile fail\n"); + usleep(100); + continue; + } + offset += sendsize; + } + gettimeofday(&t_end, NULL); + printf("time cost is: %lfms.\n", (t_end.tv_sec-t_start.tv_sec)*1000.0+(t_end.tv_usec-t_start.tv_usec)/1000.0); + + close(fd); + close(sockfd); + + return 0; +} diff --git a/offloading_binaries/Sendfile_lo/sendfile_lo b/offloading_binaries/Sendfile_lo/sendfile_lo new file mode 100755 index 0000000..0b26bc9 Binary files /dev/null and b/offloading_binaries/Sendfile_lo/sendfile_lo differ diff --git a/offloading_binaries/Sendfile_usb/Makefile b/offloading_binaries/Sendfile_usb/Makefile new file mode 100644 index 0000000..85a0d83 --- /dev/null +++ b/offloading_binaries/Sendfile_usb/Makefile @@ -0,0 +1,20 @@ +CC = arm-linux-androideabi-gcc +CFLAGS = -pie -fPIE +TARGET = sendfile_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/Sendfile_usb/main.c b/offloading_binaries/Sendfile_usb/main.c new file mode 100644 index 0000000..9c1fc4c --- /dev/null +++ b/offloading_binaries/Sendfile_usb/main.c @@ -0,0 +1,128 @@ +/* + * 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 "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; + + int sockfd; + 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; + int outstanding; + + + struct sockaddr_in servaddr; + + 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("10.42.0.1"); + 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) + { + ret = sendfile(sockfd, fd, (off_t *)&offset, quota - sentInSlot); +// printf("err: %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++; + + //ioctl(sockfd, SIOCOUTQ, &outstanding); + //if (outstanding > 0) + //{ + // continue; + //} + //ret = sendfile(sockfd, fd, (off_t *)&offset, 4096); + + } + 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/Sendfile_usb/main.o b/offloading_binaries/Sendfile_usb/main.o new file mode 100644 index 0000000..89527e8 Binary files /dev/null and b/offloading_binaries/Sendfile_usb/main.o differ diff --git a/offloading_binaries/Sendfile_usb/sendfile_usb b/offloading_binaries/Sendfile_usb/sendfile_usb new file mode 100755 index 0000000..278a5d8 Binary files /dev/null and b/offloading_binaries/Sendfile_usb/sendfile_usb differ diff --git a/offloading_binaries/Splice/Makefile b/offloading_binaries/Splice/Makefile new file mode 100644 index 0000000..e472f73 --- /dev/null +++ b/offloading_binaries/Splice/Makefile @@ -0,0 +1,20 @@ +CC = arm-linux-androideabi-gcc +CFLAGS = -pie -fPIE +TARGET = splice + +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/main.c b/offloading_binaries/Splice/main.c new file mode 100644 index 0000000..71cc7b6 --- /dev/null +++ b/offloading_binaries/Splice/main.c @@ -0,0 +1,172 @@ +/* + * 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 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=0, sendsize=1488, packet_num, offset = 0; + int fd; /* file descriptor for file to send */ + int outstanding; + struct timeval t_start,t_end,t_now; + ssize_t bytes, bytes_sent, bytes_in_pipe; + size_t total_bytes_sent = 0; + + int filedes [2]; + ret = pipe (filedes); + + struct sockaddr_in servaddr; + + 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); + + connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)); + + fd = open("/data/local/tmp/bigfile", O_RDONLY); + 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); + while (total_bytes_sent < packet_num) + { + if ((packet_num - total_bytes_sent) < quota) + { + quota = packet_num - offset; + } + + while (sentInSlot < quota) + { + // Splice the data from in_fd into the pipe + if ((bytes_sent = splice(fd, NULL, filedes[1], NULL, + quota - sentInSlot, + 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; + } + perror("splice"); + return -1; + } + + // 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, sockfd, 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; + } + perror("splice"); + return -1; + } + bytes_in_pipe -= bytes; + } + total_bytes_sent += bytes_sent; + sentInSlot += bytes_sent; + } + + 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++; + + /* + for(;;) + { + ioctl(sockfd, SIOCOUTQ, &outstanding); + printf("outstanding:%d\n", outstanding); + if (outstanding>0) + { + usleep(100); + } + else + { + break; + } + } + */ + } + 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/splice b/offloading_binaries/Splice/splice new file mode 100755 index 0000000..7cdec1d Binary files /dev/null and b/offloading_binaries/Splice/splice differ diff --git a/offloading_binaries/Splice_lo/Makefile b/offloading_binaries/Splice_lo/Makefile new file mode 100644 index 0000000..8b890ac --- /dev/null +++ b/offloading_binaries/Splice_lo/Makefile @@ -0,0 +1,20 @@ +CC = arm-linux-androideabi-gcc +CFLAGS = -pie -fPIE +TARGET = splice_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_lo/main.c b/offloading_binaries/Splice_lo/main.c new file mode 100644 index 0000000..2268c14 --- /dev/null +++ b/offloading_binaries/Splice_lo/main.c @@ -0,0 +1,172 @@ +/* + * 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 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=0, sendsize=1488, packet_num, offset = 0; + int fd; /* file descriptor for file to send */ + int outstanding; + struct timeval t_start,t_end,t_now; + ssize_t bytes, bytes_sent, bytes_in_pipe; + size_t total_bytes_sent = 0; + + int filedes [2]; + ret = pipe (filedes); + + struct sockaddr_in servaddr; + + 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); + + connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)); + + fd = open("/data/local/tmp/bigfile", O_RDONLY); + 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); + while (total_bytes_sent < packet_num) + { + if ((packet_num - total_bytes_sent) < quota) + { + quota = packet_num - offset; + } + + while (sentInSlot < quota) + { + // Splice the data from in_fd into the pipe + if ((bytes_sent = splice(fd, NULL, filedes[1], NULL, + quota - sentInSlot, + 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; + } + perror("splice"); + return -1; + } + + // 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, sockfd, 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; + } + perror("splice"); + return -1; + } + bytes_in_pipe -= bytes; + } + total_bytes_sent += bytes_sent; + sentInSlot += bytes_sent; + } + + 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++; + + /* + for(;;) + { + ioctl(sockfd, SIOCOUTQ, &outstanding); + printf("outstanding:%d\n", outstanding); + if (outstanding>0) + { + usleep(100); + } + else + { + break; + } + } + */ + } + 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_lo/main.o b/offloading_binaries/Splice_lo/main.o new file mode 100644 index 0000000..59f706c Binary files /dev/null and b/offloading_binaries/Splice_lo/main.o differ diff --git a/offloading_binaries/Splice_lo/splice_lo b/offloading_binaries/Splice_lo/splice_lo new file mode 100755 index 0000000..5619894 Binary files /dev/null and b/offloading_binaries/Splice_lo/splice_lo differ diff --git a/offloading_binaries/Splice_recv/Makefile b/offloading_binaries/Splice_recv/Makefile new file mode 100644 index 0000000..253d69d --- /dev/null +++ b/offloading_binaries/Splice_recv/Makefile @@ -0,0 +1,20 @@ +CC = arm-linux-androideabi-gcc +CFLAGS = -pie -fPIE +TARGET = splice_recv + +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/main.c b/offloading_binaries/Splice_recv/main.c new file mode 100644 index 0000000..873124f --- /dev/null +++ b/offloading_binaries/Splice_recv/main.c @@ -0,0 +1,177 @@ +/* + * 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 new file mode 100755 index 0000000..a9fa812 Binary files /dev/null and b/offloading_binaries/Splice_recv/splice_recv differ diff --git a/offloading_binaries/Splice_recv_lo/Makefile b/offloading_binaries/Splice_recv_lo/Makefile new file mode 100644 index 0000000..55a3e25 --- /dev/null +++ b/offloading_binaries/Splice_recv_lo/Makefile @@ -0,0 +1,20 @@ +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 new file mode 100644 index 0000000..4826c59 --- /dev/null +++ b/offloading_binaries/Splice_recv_lo/main.c @@ -0,0 +1,176 @@ +/* + * 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 new file mode 100644 index 0000000..9f831b1 Binary files /dev/null and b/offloading_binaries/Splice_recv_lo/main.o differ diff --git a/offloading_binaries/Splice_recv_lo/splice_recv_lo b/offloading_binaries/Splice_recv_lo/splice_recv_lo new file mode 100755 index 0000000..2950e70 Binary files /dev/null and b/offloading_binaries/Splice_recv_lo/splice_recv_lo differ diff --git a/offloading_binaries/TCPReceiver_mobile/Makefile b/offloading_binaries/TCPReceiver_mobile/Makefile new file mode 100644 index 0000000..8913c1d --- /dev/null +++ b/offloading_binaries/TCPReceiver_mobile/Makefile @@ -0,0 +1,21 @@ +#CC = /media/Lucifer/android/lib/android-18-toolchain/bin/arm-linux-androideabi-gcc +CC = arm-linux-androideabi-gcc +CFLAGS = -pie -fPIE +TARGET = TCPReceiver_mobile + +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 $@ + +clean: + -rm -f *.o + -rm -f $(TARGET) diff --git a/offloading_binaries/TCPReceiver_mobile/TCPReceiver_mobile b/offloading_binaries/TCPReceiver_mobile/TCPReceiver_mobile new file mode 100755 index 0000000..63c2997 Binary files /dev/null and b/offloading_binaries/TCPReceiver_mobile/TCPReceiver_mobile differ diff --git a/offloading_binaries/TCPReceiver_mobile/main.c b/offloading_binaries/TCPReceiver_mobile/main.c new file mode 100644 index 0000000..a9ddd13 --- /dev/null +++ b/offloading_binaries/TCPReceiver_mobile/main.c @@ -0,0 +1,121 @@ +/* + * 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 + +#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, 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=1488, packet_num=1000000000, 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; + + signal(SIGPIPE, SIG_IGN); + + if (argc > 1) + port = atoi(argv[1]); + else + { + printf("Usage: TCPServer port rate"); + exit(1); + } + + if (argc > 2) + packet_num = atoi(argv[2]); + + + listenfd = socket(AF_INET, SOCK_STREAM, 0); + + + bzero(&servaddr,sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = htonl(INADDR_ANY); + servaddr.sin_port = htons(port); + bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr)); + listen(listenfd, 1); + + for(;;) + { + clilen=sizeof(cliaddr); + sockfd = accept(listenfd,(struct sockaddr *)&cliaddr, &clilen); + printf("Accepted.\n"); + //setsockopt(sd, SOL_SOCKET, SO_NOSIGPIPE, (void *)&set, sizeof(int)); + +// fd = open("/data/local/tmp/bigfile_w", O_WRONLY | O_CREAT | O_TRUNC); + offset = 0; + + if (fd == -1) { + fprintf(stderr, "unable to open the file.\n"); + exit(1); + } + + gettimeofday(&t_start, NULL); + while (offset < packet_num) + { + ret = recv(sockfd, sendbuf, 4096, 0); + if (ret <= 0) + { + printf("recv fail\n"); + usleep(100); + break; + } +// write(fd, sendbuf, ret); + 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/TCPReceiver_mobile/main.o b/offloading_binaries/TCPReceiver_mobile/main.o new file mode 100644 index 0000000..3401c9a Binary files /dev/null and b/offloading_binaries/TCPReceiver_mobile/main.o differ diff --git a/offloading_binaries/TCPSender_mobile/Makefile b/offloading_binaries/TCPSender_mobile/Makefile new file mode 100644 index 0000000..a51dee7 --- /dev/null +++ b/offloading_binaries/TCPSender_mobile/Makefile @@ -0,0 +1,21 @@ +CC = /media/Lucifer/android/lib/android-18-toolchain/bin/arm-linux-androideabi-gcc +#CC = arm-linux-androideabi-gcc +CFLAGS = -pie -fPIE +TARGET = TCPSender_mobile + +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 $@ + +clean: + -rm -f *.o + -rm -f $(TARGET) diff --git a/offloading_binaries/TCPSender_mobile/TCPSender_mobile b/offloading_binaries/TCPSender_mobile/TCPSender_mobile new file mode 100755 index 0000000..399a563 Binary files /dev/null and b/offloading_binaries/TCPSender_mobile/TCPSender_mobile differ diff --git a/offloading_binaries/TCPSender_mobile/main.c b/offloading_binaries/TCPSender_mobile/main.c new file mode 100644 index 0000000..5c14665 --- /dev/null +++ b/offloading_binaries/TCPSender_mobile/main.c @@ -0,0 +1,133 @@ +/* + * 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 + +#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, 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=1488, packet_num=1000000000, 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; + + signal(SIGPIPE, SIG_IGN); + + if (argc > 1) + port = atoi(argv[1]); + else + { + printf("Usage: TCPServer port rate"); + exit(1); + } + + if (argc > 2) + quota = atoi(argv[2]) / (1000000 / slotLength); + + + listenfd = socket(AF_INET, SOCK_STREAM, 0); + + + bzero(&servaddr,sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = htonl(INADDR_ANY); + servaddr.sin_port = htons(port); + bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr)); + listen(listenfd, 1); + + for(;;) + { + clilen=sizeof(cliaddr); + sockfd = accept(listenfd,(struct sockaddr *)&cliaddr, &clilen); + printf("Accepted.\n"); + //setsockopt(sd, SOL_SOCKET, SO_NOSIGPIPE, (void *)&set, sizeof(int)); + + gettimeofday(&t_start, NULL); + while (offset < packet_num) + { + if ((packet_num - offset) < quota) + { + quota = packet_num - offset; + } + while (sentInSlot < quota) + { + ret = send(sockfd, sendbuf, (quota - sentInSlot < 4096) ? quota - sentInSlot : 4096, 0); + if (ret <= 0) + { + printf("send fail\n"); + slot = 1; + sentInSlot = 0; + offset = 0; + goto RESTART; + } + 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++; + + } +RESTART: + 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/TCPSender_mobile/main.o b/offloading_binaries/TCPSender_mobile/main.o new file mode 100644 index 0000000..2e8738b Binary files /dev/null and b/offloading_binaries/TCPSender_mobile/main.o differ diff --git a/offloading_binaries/TCPServer/Makefile b/offloading_binaries/TCPServer/Makefile new file mode 100644 index 0000000..6f47b9e --- /dev/null +++ b/offloading_binaries/TCPServer/Makefile @@ -0,0 +1,20 @@ +CC = gcc +CFLAGS = -pie -fPIE +TARGET = TCPServer + +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 $@ + +clean: + -rm -f *.o + -rm -f $(TARGET) diff --git a/offloading_binaries/TCPServer/TCPServer b/offloading_binaries/TCPServer/TCPServer new file mode 100755 index 0000000..cf04ffd Binary files /dev/null and b/offloading_binaries/TCPServer/TCPServer differ diff --git a/offloading_binaries/TCPServer/main.c b/offloading_binaries/TCPServer/main.c new file mode 100644 index 0000000..5c14665 --- /dev/null +++ b/offloading_binaries/TCPServer/main.c @@ -0,0 +1,133 @@ +/* + * 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 + +#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, 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=1488, packet_num=1000000000, 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; + + signal(SIGPIPE, SIG_IGN); + + if (argc > 1) + port = atoi(argv[1]); + else + { + printf("Usage: TCPServer port rate"); + exit(1); + } + + if (argc > 2) + quota = atoi(argv[2]) / (1000000 / slotLength); + + + listenfd = socket(AF_INET, SOCK_STREAM, 0); + + + bzero(&servaddr,sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = htonl(INADDR_ANY); + servaddr.sin_port = htons(port); + bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr)); + listen(listenfd, 1); + + for(;;) + { + clilen=sizeof(cliaddr); + sockfd = accept(listenfd,(struct sockaddr *)&cliaddr, &clilen); + printf("Accepted.\n"); + //setsockopt(sd, SOL_SOCKET, SO_NOSIGPIPE, (void *)&set, sizeof(int)); + + gettimeofday(&t_start, NULL); + while (offset < packet_num) + { + if ((packet_num - offset) < quota) + { + quota = packet_num - offset; + } + while (sentInSlot < quota) + { + ret = send(sockfd, sendbuf, (quota - sentInSlot < 4096) ? quota - sentInSlot : 4096, 0); + if (ret <= 0) + { + printf("send fail\n"); + slot = 1; + sentInSlot = 0; + offset = 0; + goto RESTART; + } + 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++; + + } +RESTART: + 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/TCPServer/main.o b/offloading_binaries/TCPServer/main.o new file mode 100644 index 0000000..3d36357 Binary files /dev/null and b/offloading_binaries/TCPServer/main.o differ diff --git a/offloading_binaries/UDPReceiver_mobile/Makefile b/offloading_binaries/UDPReceiver_mobile/Makefile new file mode 100644 index 0000000..7747fa4 --- /dev/null +++ b/offloading_binaries/UDPReceiver_mobile/Makefile @@ -0,0 +1,21 @@ +#CC = /media/Lucifer/android/lib/android-18-toolchain/bin/arm-linux-androideabi-gcc +CC = arm-linux-androideabi-gcc +CFLAGS = -pie -fPIE +TARGET = UDPReceiver_mobile + +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 $@ + +clean: + -rm -f *.o + -rm -f $(TARGET) diff --git a/offloading_binaries/UDPReceiver_mobile/UDPReceiver_mobile b/offloading_binaries/UDPReceiver_mobile/UDPReceiver_mobile new file mode 100755 index 0000000..492c9f7 Binary files /dev/null and b/offloading_binaries/UDPReceiver_mobile/UDPReceiver_mobile differ diff --git a/offloading_binaries/UDPReceiver_mobile/main.c b/offloading_binaries/UDPReceiver_mobile/main.c new file mode 100644 index 0000000..3d83642 --- /dev/null +++ b/offloading_binaries/UDPReceiver_mobile/main.c @@ -0,0 +1,97 @@ +/* + * 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 + +#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, 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=1488, packet_num=1000000000, 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; + + signal(SIGPIPE, SIG_IGN); + + if (argc > 1) + port = atoi(argv[1]); + else + { + printf("Usage: TCPServer port rate"); + exit(1); + } + + if (argc > 2) + packet_num = atoi(argv[2]); + + + listenfd = socket(AF_INET, SOCK_DGRAM, 0); + + + bzero(&servaddr,sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = htonl(INADDR_ANY); + servaddr.sin_port = htons(port); + bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr)); +// listen(listenfd, 1); + + for(;;) + { + clilen=sizeof(cliaddr); + ret = recvfrom(listenfd,sendbuf, 4096, 0, (struct sockaddr *)&cliaddr, &clilen); +// sockfd = accept(listenfd,(struct sockaddr *)&cliaddr, &clilen); + printf("Accepted.\n"); + + } + + close(fd); + + return 0; +} diff --git a/offloading_binaries/UDPReceiver_mobile/main.o b/offloading_binaries/UDPReceiver_mobile/main.o new file mode 100644 index 0000000..1cdaf9b Binary files /dev/null and b/offloading_binaries/UDPReceiver_mobile/main.o differ diff --git a/offloading_binaries/UDPSender/Makefile b/offloading_binaries/UDPSender/Makefile new file mode 100644 index 0000000..87b8e37 --- /dev/null +++ b/offloading_binaries/UDPSender/Makefile @@ -0,0 +1,20 @@ +CC = gcc +CFLAGS = -Wall +TARGET = UDPSender + +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) $(CFLAGS) -o $@ + +clean: + -rm -f *.o + -rm -f $(TARGET) diff --git a/offloading_binaries/UDPSender/UDPSender b/offloading_binaries/UDPSender/UDPSender new file mode 100755 index 0000000..a02851a Binary files /dev/null and b/offloading_binaries/UDPSender/UDPSender differ diff --git a/offloading_binaries/UDPSender/main.c b/offloading_binaries/UDPSender/main.c new file mode 100644 index 0000000..15ca5a0 --- /dev/null +++ b/offloading_binaries/UDPSender/main.c @@ -0,0 +1,125 @@ +/* + * 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. + */ +//#define _BSD_SOURCE +#include +//#include +#include +#include +#include +#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 +//ca:e0:eb:61:b7:64 +#define MY_DEST_MAC0 0xca +#define MY_DEST_MAC1 0xe0 +#define MY_DEST_MAC2 0xeb +#define MY_DEST_MAC3 0x61 +#define MY_DEST_MAC4 0xb7 +#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=1000000000, 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; + + signal(SIGPIPE, SIG_IGN); + + if (argc > 1) + quota = atoi(argv[1]) / (1000000 / slotLength); + else + { + printf("Usage: UDPSender rate"); + exit(1); + } + for (i = 0; i < sendsize; i++) sendbuf[i] = '0'; + // fix packet size problem + packetPerSlot = ceil(((double)quota) / sendsize); + slotLength = (int)(packetPerSlot * sendsize / quota * slotLength); + quota = (int)packetPerSlot * sendsize; + //printf("TESThere1"); + 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.2.2"); + servaddr.sin_port=htons(4444); + //printf("testhere1"); + 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); + } + offset += ret; + sentInSlot = sentInSlot + ret; + } +//printf("here3"); + 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(fd); + + return 0; +} diff --git a/offloading_binaries/UDPServer/Makefile b/offloading_binaries/UDPServer/Makefile new file mode 100644 index 0000000..aab23bd --- /dev/null +++ b/offloading_binaries/UDPServer/Makefile @@ -0,0 +1,20 @@ +CC = gcc +CFLAGS = -pie -fPIE +TARGET = UDPServer + +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 UDPServer ~/mobileRDMABeach/ +clean: + -rm -f *.o + -rm -f $(TARGET) diff --git a/offloading_binaries/UDPServer/UDPServer b/offloading_binaries/UDPServer/UDPServer new file mode 100755 index 0000000..7b054bc Binary files /dev/null and b/offloading_binaries/UDPServer/UDPServer differ diff --git a/offloading_binaries/UDPServer/main.c b/offloading_binaries/UDPServer/main.c new file mode 100644 index 0000000..47c4868 --- /dev/null +++ b/offloading_binaries/UDPServer/main.c @@ -0,0 +1,149 @@ +/* + * 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 + +#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, defaulttimeperiod = 500000000; + double elapsedTime; + + 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=1000000000, 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; + + signal(SIGPIPE, SIG_IGN); + + if (argc > 1) + port = atoi(argv[1]); + else + { + printf("Usage: UDPServer port rate"); + exit(1); + } + + if (argc > 2) + quota = atoi(argv[2]) / (1000000 / slotLength); + + if (argc > 3) + defaulttimeperiod = atoi(argv[3])*1000000; + + listenfd = socket(AF_INET, SOCK_DGRAM, 0); + +// printf("listen"); + bzero(&servaddr,sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = htonl(INADDR_ANY); + servaddr.sin_port = htons(port); + bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr)); +// listen(listenfd, 1); +// printf("bind"); + for(;;) + { + clilen=sizeof(cliaddr); + printf("start receiving..\n"); + ret = recvfrom(listenfd,sendbuf,4096, 0, (struct sockaddr *)&cliaddr, &clilen); +// printf("msg: %s\n",sendbuf); + if (sendbuf[0] == '0') { + printf("Accepted.\n"); + gettimeofday(&t_start, NULL); + for (i = 0; i < BUF_SIZ; i++) sendbuf[i] = '0'; + while (offset < packet_num) + { + if ((packet_num - offset) < quota) + { + quota = packet_num - offset; + } + while (sentInSlot < quota) + { + ret = sendto(listenfd, sendbuf, sendsize, 0, (struct sockaddr *)&cliaddr, sizeof(cliaddr)); + if (ret < sendsize) + { + printf("send fail\n"); + slot = 1; + sentInSlot = 0; + offset = 0; + goto RESTART; + } + 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 > defaulttimeperiod) { + slot = 1; + sentInSlot = 0; + offset = 0; + goto AUTOCLOSE; + } + //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++; + + } +// sockfd = accept(listenfd,(struct sockaddr *)&cliaddr, &clilen); + } + + + RESTART: + // 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); + } + AUTOCLOSE: + 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/UDPServer/main.o b/offloading_binaries/UDPServer/main.o new file mode 100644 index 0000000..17d23e6 Binary files /dev/null and b/offloading_binaries/UDPServer/main.o differ diff --git a/offloading_binaries/UDPServer_mobile/Makefile b/offloading_binaries/UDPServer_mobile/Makefile new file mode 100644 index 0000000..a087f67 --- /dev/null +++ b/offloading_binaries/UDPServer_mobile/Makefile @@ -0,0 +1,21 @@ +CC = /media/Lucifer/android/lib/android-18-toolchain/bin/arm-linux-androideabi-gcc +#CC = gcc +CFLAGS = -pie -fPIE +TARGET = UDPServer_mobile + +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 UDPServer ~/mobileRDMABeach/ +clean: + -rm -f *.o + -rm -f $(TARGET) diff --git a/offloading_binaries/UDPServer_mobile/UDPServer_mobile b/offloading_binaries/UDPServer_mobile/UDPServer_mobile new file mode 100755 index 0000000..dae2600 Binary files /dev/null and b/offloading_binaries/UDPServer_mobile/UDPServer_mobile differ diff --git a/offloading_binaries/UDPServer_mobile/main.c b/offloading_binaries/UDPServer_mobile/main.c new file mode 100644 index 0000000..47c4868 --- /dev/null +++ b/offloading_binaries/UDPServer_mobile/main.c @@ -0,0 +1,149 @@ +/* + * 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 + +#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, defaulttimeperiod = 500000000; + double elapsedTime; + + 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=1000000000, 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; + + signal(SIGPIPE, SIG_IGN); + + if (argc > 1) + port = atoi(argv[1]); + else + { + printf("Usage: UDPServer port rate"); + exit(1); + } + + if (argc > 2) + quota = atoi(argv[2]) / (1000000 / slotLength); + + if (argc > 3) + defaulttimeperiod = atoi(argv[3])*1000000; + + listenfd = socket(AF_INET, SOCK_DGRAM, 0); + +// printf("listen"); + bzero(&servaddr,sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = htonl(INADDR_ANY); + servaddr.sin_port = htons(port); + bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr)); +// listen(listenfd, 1); +// printf("bind"); + for(;;) + { + clilen=sizeof(cliaddr); + printf("start receiving..\n"); + ret = recvfrom(listenfd,sendbuf,4096, 0, (struct sockaddr *)&cliaddr, &clilen); +// printf("msg: %s\n",sendbuf); + if (sendbuf[0] == '0') { + printf("Accepted.\n"); + gettimeofday(&t_start, NULL); + for (i = 0; i < BUF_SIZ; i++) sendbuf[i] = '0'; + while (offset < packet_num) + { + if ((packet_num - offset) < quota) + { + quota = packet_num - offset; + } + while (sentInSlot < quota) + { + ret = sendto(listenfd, sendbuf, sendsize, 0, (struct sockaddr *)&cliaddr, sizeof(cliaddr)); + if (ret < sendsize) + { + printf("send fail\n"); + slot = 1; + sentInSlot = 0; + offset = 0; + goto RESTART; + } + 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 > defaulttimeperiod) { + slot = 1; + sentInSlot = 0; + offset = 0; + goto AUTOCLOSE; + } + //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++; + + } +// sockfd = accept(listenfd,(struct sockaddr *)&cliaddr, &clilen); + } + + + RESTART: + // 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); + } + AUTOCLOSE: + 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/UDPServer_mobile/main.o b/offloading_binaries/UDPServer_mobile/main.o new file mode 100644 index 0000000..0bc3200 Binary files /dev/null and b/offloading_binaries/UDPServer_mobile/main.o differ diff --git a/offloading_binaries/old/parseSS.py b/offloading_binaries/old/parseSS.py new file mode 100755 index 0000000..90abf46 --- /dev/null +++ b/offloading_binaries/old/parseSS.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python +import sys +# Yanzi + +wifiRSS = [] +gsmRSS = [] + +with open(sys.argv[1], 'rU') as f: # it must be sorted + for line in f: + tmp = line.split(" ") + time = int(tmp[0]) # ms + stuff = tmp[1:] + if "wifi" in stuff: + wifiRSS.append( (time, stuff) ) + elif "gsm" in stuff: + gsmRSS.append( (time, stuff) ) + +wifilen = len(wifiRSS) +gsmlen = len(gsmRSS) +print "WiFi has {0} records, GSM has {1} records".format(wifilen, gsmlen) + +for i in range(wifilen-1): + start = False + for j in range(wifiRSS[i][0], wifiRSS[i+1][0], 50): + if not start: + start = True + continue + wifiRSS.append((j, wifiRSS[i][1])) + +wifiRSS.sort(key=lambda tup: tup[0]) +# print wifiRSS + +for i in range(gsmlen-1): + start = False + for j in range(gsmRSS[i][0], gsmRSS[i+1][0], 50): + if not start: + start = True + continue + gsmRSS.append((j, gsmRSS[i][1])) + +gsmRSS.sort(key=lambda tup: tup[0]) +# print gsmRSS + + +