示例#1
0
int main(int argc, char *argv[]) {
        int arg_offset;

        const char *progname = argv[0];

        if ((arg_offset = onvm_nf_init(argc, argv, NF_TAG)) < 0)
                return -1;
        argc -= arg_offset;
        argv += arg_offset;

        if (parse_app_args(argc, argv, progname) < 0)
                rte_exit(EXIT_FAILURE, "Invalid command-line arguments\n");

        struct rte_mempool *pktmbuf_pool;
        struct rte_mbuf* pkts[NUM_PKTS];
        int i;

        pktmbuf_pool = rte_mempool_lookup(PKTMBUF_POOL_NAME);
        if(pktmbuf_pool == NULL) {
                rte_exit(EXIT_FAILURE, "Cannot find mbuf pool!\n");
        }
        printf("Creating %d packets to send to %d\n", NUM_PKTS, destination);
        for (i=0; i < NUM_PKTS; i++) {
                struct onvm_pkt_meta* pmeta;
                pkts[i] = rte_pktmbuf_alloc(pktmbuf_pool);
                pmeta = onvm_get_pkt_meta(pkts[i]);
                pmeta->destination = destination;
                pmeta->action = ONVM_NF_ACTION_TONF;
                pkts[i]->port = 3;
                pkts[i]->hash.rss = i;
                onvm_nf_return_pkt(pkts[i]);
        }

        onvm_nf_run(nf_info, &packet_handler);
        printf("If we reach here, program is ending");
        return 0;
}
示例#2
0
文件: main.c 项目: mjycom/nids
int main(int argc, char *argv[]) {
        int arg_offset;

        const char *progname = argv[0];

        if ((arg_offset = onvm_nf_init(argc, argv, NF_TAG)) < 0)
                return -1;
        argc -= arg_offset;
        argv += arg_offset;

        if (parse_app_args(argc, argv, progname) < 0)
                rte_exit(EXIT_FAILURE, "Invalid command-line arguments\n");

		// NIDS
		// Init ...
		flag_start = 0;
		flag_counter = 0;
		flag_packets = 0;
		blockNum = 11;
		threadNum = 1024;
		batchSize = 983040;
		pkt_calculate = 0;

/*		packets = (char *)malloc(batchSize * blockNum * threadNum * MAX_LEN * sizeof(char));
		packets_len = (uint16_t *)malloc(batchSize * blockNum * threadNum * sizeof(uint16_t));
		memset(packets, 0, batchSize * blockNum * threadNum * MAX_LEN * sizeof(char));
		memset(packets_len, 0, batchSize * blockNum * threadNum * sizeof(uint16_t));
		packets2 = (char *)malloc(batchSize * blockNum * threadNum * MAX_LEN * sizeof(char));
		packets_len2 = (uint16_t *)malloc(batchSize * blockNum * threadNum * sizeof(uint16_t));
		memset(packets2, 0, batchSize * blockNum * threadNum * MAX_LEN * sizeof(char));
		memset(packets_len2, 0, batchSize * blockNum * threadNum * sizeof(uint16_t));
*/
		int i = 0;
		packets = (char **)malloc(PKTS_NUM * sizeof(char *));
		for(i = 0; i < PKTS_NUM;i ++)
		{
			packets[i] = (char *)malloc(batchSize * MAX_LEN * sizeof(char));
		}
		packets_len = (uint16_t **)malloc(PKTS_NUM * sizeof(uint16_t *));
		for(i = 0; i < PKTS_NUM;i ++)
		{
			packets_len[i] = (uint16_t *)malloc(batchSize * sizeof(uint16_t));
		}

		char rules_path[20]; // "community.rules";
		rules_path[0] = 't';
		rules_path[1] = 'r';
		rules_path[2] = '\0';

		ListRoot *listroot;
		listroot = configrules((char *)rules_path);
		precreatearray(listroot);
		test(listroot);

		rsr = listroot->TcpListRoot->prmGeneric->rsr;
		gpuinit(rsr, blockNum, threadNum, batchSize, &acGPU, &pkt_cuda, &pkt_len, &res);

        // Create matching thread
		int ret;
		pthread_t pid;
		ret = pthread_create(&pid, NULL, (void *)&nids_match, NULL);
		if(ret != 0)
		{
			printf("!!!!!!Error: create pthread error!\n");
			return 0;
		}


		// Run...
		onvm_nf_run(nf_info, &packet_handler);
        printf("If we reach here, program is ending");
		
	clock_gettime(CLOCK_MONOTONIC, &ts2);
//	printf("stop!!\n");
	struct timespec temp = diff(ts1, ts2);
	//double mpps = (double)(batchSize * ITERATION) / (double)(temp.tv_sec * 1000000 + temp.tv_nsec / 1000);
	double mpps = (double)(batchSize * pkt_calculate) / (double)(temp.tv_sec * 1000000 + temp.tv_nsec / 1000);
	double gbps = (mpps * 1000 * 8) / 1000;
	printf("\n");
	printf("BatchSize is %d, batchNum is %d\n", batchSize, pkt_calculate);
	printf("Throughput is %lf Gbps\n", gbps);
		// Free...
		gpufree(0, acGPU, pkt_cuda, pkt_len, res);
		freeall(listroot);
		printf("End.\n");
        return 0;
}