X-Git-Url: http://git.sameswireless.fr/l2tpns.git/blobdiff_plain/4ef684093db97124d3c3d57b855fc844d02a379b..refs/heads/pppoe-srv:/test/generateload.c diff --git a/test/generateload.c b/test/generateload.c index c3a40b6..b671b4f 100644 --- a/test/generateload.c +++ b/test/generateload.c @@ -1,3 +1,9 @@ +#define _POSIX_C_SOURCE 200112L +#include +#include +#include +#define __USE_XOPEN_EXTENDED +#define __USE_MISC #include #include #include @@ -6,11 +12,8 @@ #include #include #include -#include -#include #include #include -#include #include #include #include @@ -179,10 +182,10 @@ typedef struct } control_message; typedef struct { -unsigned long long send_count , recv_count ; -unsigned long long spkt , rpkt ; -unsigned int dropped; -unsigned long sbytes , rbytes ; +long long send_count, recv_count; +long long spkt, rpkt ; +int dropped; +long sbytes, rbytes ; int quitit; struct sessiont { @@ -210,7 +213,7 @@ void dump_control_message(control_message *c); u32 avp_get_32(control_message *c, int id); u16 avp_get_16(control_message *c, int id); char *avp_get_s(control_message *c, int id); -void reader_thread(int udpfd); +void reader_thread(void); void skip_zlb(); void cm_free(control_message *m); controlt *ppp_new(u16 session, int protocol); @@ -231,12 +234,10 @@ void sigint(int signal); void clean_shutdown(); void print_report(); -pthread_t pthread_reader; - int ns = 0, nr = 0; int udpfd; int t = 0; -struct sockaddr_in gatewayaddr = {0}; +struct sockaddr_in gatewayaddr; int numsessions = NUM_SESSIONS; int packet_length = PACKET_LENGTH; int target_pps = TARGET_PPS; @@ -253,7 +254,7 @@ char *suffix = "@optusnet.com.au"; int main(int argc, char *argv[]) { int s; - char *packet; + unsigned char *packet; ss = (sharedt*) mmap(NULL, sizeof(*ss), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); @@ -286,7 +287,7 @@ int main(int argc, char *argv[]) break; case 'm' : max_packets = atoi(optarg); - if (packet_length < 64) + if (max_packets < 50) { printf("You must send at least 50 packets.\n"); return -1; @@ -379,6 +380,7 @@ int main(int argc, char *argv[]) printf("Bound to port %d\n", htons(addr.sin_port)); }/*}}}*/ + memset(&gatewayaddr, 0, sizeof(gatewayaddr)); gatewayaddr.sin_family = AF_INET; gatewayaddr.sin_port = htons(1701); inet_aton(gwaddr, &gatewayaddr.sin_addr); @@ -402,7 +404,8 @@ int main(int argc, char *argv[]) // Receive reply/*{{{*/ { struct sockaddr_in addr; - int alen = sizeof(addr), l; + int l; + socklen_t alen = sizeof(addr); l = recvfrom(udpfd, packet, 4096, 0, (void *) &addr, &alen); if (l < 0) @@ -411,7 +414,7 @@ int main(int argc, char *argv[]) return -1; } printf("Received "); - r = parsecontrol(packet, l); + r = parsecontrol((char *) packet, l); if (!r->first) { printf("Invalid packet.. no first avp\n"); @@ -448,7 +451,7 @@ int main(int argc, char *argv[]) printf("All session create requests sent...\n");/*}}}*/ if ( fork() == 0) { - reader_thread(udpfd); + reader_thread(); exit(0); } @@ -531,7 +534,7 @@ int main(int argc, char *argv[]) *(u16 *)(c->buf + 4) = htons(ss->sessions[i].remote_session); // Session ID iph->saddr = ss->sessions[i].addr; iph->check = 0; - iph->check = ntohs(checksum((char *)iph, sizeof(struct iphdr))); + iph->check = ntohs(checksum((unsigned char *)iph, sizeof(struct iphdr))); *((unsigned int *) data) = seq++; ppp_send(c); @@ -548,7 +551,8 @@ int main(int argc, char *argv[]) nanosleep(&req, NULL); } - if (max_packets && ss->send_count >= max_packets) ss->quitit++; + if (max_packets && ss->send_count >= max_packets) + ss->quitit++; } } @@ -604,22 +608,24 @@ void clean_shutdown()/*{{{*/ } }/*}}}*/ -void sigint(int signal) +void sigint(int unused __attribute__ ((unused))) { ss->quitit++; } -void sigalarm(int junk) +void sigalarm(int unused __attribute__ ((unused))) { static unsigned long long last_rpkts[AVG_SIZE], last_spkts[AVG_SIZE]; static int last = 0, avg_count = 0; - register unsigned int avg_s = 0, avg_r = 0, i; + unsigned int avg_s = 0, avg_r = 0; + int i; float loss; last_rpkts[last] = ss->rpkt; last_spkts[last] = ss->spkt; last = (last + 1) % AVG_SIZE; - if (avg_count < AVG_SIZE) avg_count++; + if (avg_count < AVG_SIZE) + avg_count++; for (i = 0; i < avg_count; i++) { @@ -647,14 +653,14 @@ __u16 checksum(unsigned char *addr, int count) for (; count > 1; count -= 2) { - sum += ntohs(*(u32 *)addr); + sum += ntohs(*(u16 *)addr); addr += 2; } - if (count > 1) sum += *(unsigned char *)addr; + if (count > 0) sum += *(unsigned char *)addr; // take only 16 bits out of the 32 bit sum and add up the carries - while (sum >> 16) + if (sum >> 16) sum = (sum & 0xFFFF) + (sum >> 16); // one's complement the result @@ -869,7 +875,7 @@ void cm_free(control_message *m) // }}} -void reader_thread(int updfd)/*{{{*/ +void reader_thread()/*{{{*/ { unsigned char *packet; unsigned int seq = 0; @@ -879,7 +885,7 @@ void reader_thread(int updfd)/*{{{*/ while (!ss->quitit) { struct sockaddr_in addr; - int alen = sizeof(addr); + socklen_t alen = sizeof(addr); control_message *m; int l; int s; @@ -908,7 +914,7 @@ void reader_thread(int updfd)/*{{{*/ { // Control Packet printf("Reader Received "); - m = parsecontrol(packet, l); + m = parsecontrol((char *) packet, l); printf("\n"); s = m->session; @@ -977,7 +983,7 @@ void reader_thread(int updfd)/*{{{*/ if (protocol != PPPIP) { printf("Received "); - dump_ppp_packet(packet + 6, l - 6); + dump_ppp_packet((char *) (packet + 6), l - 6); } if (protocol == PPPLCP) @@ -1025,9 +1031,9 @@ void reader_thread(int updfd)/*{{{*/ controlfree(r); break; case CONFNAK : - // Ack whatever address we are given - it's ours - r = ppp_ipcp(s, CONFACK, time(NULL) % 255); - ppp_lcp_add_option(r, 3, 4, address); // Request 0.0.0.0 + // Request whatever address we are given - it's ours + r = ppp_ipcp(s, CONFREQ, time(NULL) % 255); + ppp_lcp_add_option(r, 3, 4, address); ppp_send(r); controlfree(r); printf("Session %d: %s\n", s, inet_toa(address)); @@ -1075,13 +1081,13 @@ void reader_thread(int updfd)/*{{{*/ if (iph->protocol == 17) { - int iseq; + unsigned int iseq; ss->recv_count++; ss->rpkt++; iseq = *((unsigned int *) data); - if (seq != iseq) { + if (seq != iseq) ss->dropped += (iseq - seq) ; - } + seq = iseq + 1; // Next sequence number to expect. } } @@ -1097,7 +1103,7 @@ void reader_thread(int updfd)/*{{{*/ void skip_zlb() /*{{{*/ { struct sockaddr_in addr; - int alen = sizeof(addr); + socklen_t alen = sizeof(addr); char buf[1024]; int l; l = recvfrom(udpfd, buf, 1024, MSG_PEEK, (void *) &addr, &alen);