/****************************************************************************** description : sample application author : dawning date : 2008.09.30 ******************************************************************************/ /*Dawning Information Industry(BeiJing) Corp. Ltd. 1995~*. All Rights Reserved.*/ #include #include #include #include #include #include #include #include #include "libpag.h" #define USAG_MSG "\n *** Usage *** : %s [copynum]\n" #define THREAD_NUM 8 #define SEND_LEN 300 int COPY_PKT_TIME=0; int sids[THREAD_NUM]; unsigned char sendpkt[4000] = { 0x45,0x00,0x00,0x92,0xc7,0x6b,0x00,0x00,0x00,0x00,0x00,0x00,0xcb,0xd0,0x25,0x63,0xc0,0xa8,0x01,0xbb, //ip head 0x00,0x50,0x07,0xbb,0x78,0x28,0x73,0x3e,0x43,0x23,0x6a,0x7c,0x70,0x12,0x16,0x58,0x76,0xd4,0x00,0x00,//tcp head 0x02,0x04,0x05,0x64,0x01,0x01,0x04,0x02 }; ulong pkts[THREAD_NUM][16]; ulong bytes[THREAD_NUM][16]; ulong old_pkts[THREAD_NUM]; ulong old_bytes[THREAD_NUM]; ulong all_pkts, all_bytes; int main_loop_flag = 1; int thread_loop_flag = 1; char dist[8][2000]; void print_speed_thread(void *ptr) { int i; for(i=0; i> 17); old_pkts[i] = pkts[i][0]; old_bytes[i] = bytes[i][0]; } } } //copy pkt inline void process_pkt(int sid, void *pkt) { int i, j, len; char pkttmp[2000]; unsigned char *p8,*psend; struct iphdr* iph; //printf("process pkt at %p\n",pkt); pkts[sid][0]++; p8 = (unsigned char*)(pkt); //p8+=14; len=0; iph=(struct iphdr*)p8; len = ntohs((unsigned short)iph->tot_len); //printf("len:%d\n",len); /* printf("len:%d\n",len); for(i=0;i2) { printf(USAG_MSG, argv[0]); return -1; } if(argc ==2) COPY_PKT_TIME=atoi(argv[1]); //open a device //check returned device id if(pag_open() < 0) { printf("### Error : can not open device! ###\n"); return -1; } //create processing threads my_srand(time(NULL)); for(i=0; i pkts, <%8lu M> bytes\n", i, pkts[i][0], bytes[i][0] >> 20); all_pkts += pkts[i][0]; all_bytes += bytes[i][0]; } printf("Total : %lu pkts, %lu bytes\n", all_pkts, all_bytes); printf("Speed : < %lu > pps, < %lu M > bps\n", (ulong)(all_pkts / sec), (ulong)((all_bytes >> 17) / sec)); printf("\n"); return 0; }