/** * This creates the following chain: * __________ __________ ________ _______________ * | queue1 | -> | sampler | -> | queue2 |-> | PacketCounter | * -------- ---------- ---------- --------------- */ void ReconfTest::normalTest() { size_t nr_of_packets = 100; // must be a dividable by 2 // create a packet sampler which lets only half of the packets through // NOTICE: the sampler will be destroyed by the d'tor of FilterModule SystematicSampler* sampler = new SystematicSampler(SYSTEMATIC_SAMPLER_COUNT_BASED, 1, 1); FilterModule filter; filter.addProcessor(sampler); ConnectionQueue<Packet*> queue1(10); ConnectionQueue<Packet*> queue2(20); PrinterModule counter; counter.doPrint(false); queue1.connectTo(&filter); filter.connectTo(&queue2); queue2.connectTo(&counter); queue1.start(); queue2.start(); sendPacketsTo(&queue1, nr_of_packets); while (queue2.getCount() > 0 || queue1.getCount() > 0) { sleep(1); } ASSERT(counter.getCount() == nr_of_packets/2, "The filter hasn't eliminated half of the packets"); /** * remove the sampler and redo the test. * This time every packet should get through. * __________ __________ _______________ * | queue1 | -> | queue2 |-> | PacketCounter | * -------- ---------- --------------- */ queue1.disconnect(); queue1.connectTo(&queue2); counter.reset(); sendPacketsTo(&queue1, nr_of_packets); while (queue2.getCount() > 0|| queue1.getCount() > 0) { sleep(1); } ASSERT(counter.getCount() == nr_of_packets, "Not all packages get through"); queue1.shutdown(); queue2.shutdown(); }
/** * This creates the following chain: * _______________ * | PacketCounter | * __________ __________ / --------------- * | sampler | -> | splitter | * -------- ---------- \ _______________ * | PacketCounter | * --------------- */ void ReconfTest::splitterTest() { size_t nr_of_packets = 100; // must be a dividable by 2 PrinterModule counter1, counter2; counter1.doPrint(false); counter2.doPrint(false); // create a packet sampler which lets only half of the packets through // NOTICE: the sampler will be destroyed by the d'tor of FilterModule SystematicSampler* sampler = new SystematicSampler(SYSTEMATIC_SAMPLER_COUNT_BASED, 1, 1); FilterModule filter; filter.addProcessor(sampler); ConnectionSplitter<FilterModule::src_value_type>* splitter; splitter = new ConnectionSplitter<FilterModule::src_value_type>(); filter.connectTo(splitter); splitter->connectTo(&counter1); splitter->connectTo(&counter2); sendPacketsTo(&filter, nr_of_packets); ASSERT(counter1.getCount() == nr_of_packets/2, "The filter hasn't eliminated half of the packets for counter1"); ASSERT(counter2.getCount() == nr_of_packets/2, "The filter hasn't eliminated half of the packets for counter2"); /** * remove the sampler and redo the test. * This time every packet should get through. * __________ _______________ * | sampler| -> | PacketCounter | * -------- --------------- */ filter.disconnect(); counter1.reset(); counter2.reset(); filter.connectTo(&counter1); sendPacketsTo(&filter, nr_of_packets); ASSERT(counter1.getCount() == nr_of_packets/2, "Not all packages get through"); ASSERT(counter2.getCount() == 0, "splitter disconnect failed"); // cleanup delete splitter; }
Test::TestResult AggregationPerfTest::execTest() { // create a packet sampler which lets only half of the packets through // NOTICE: the sampler will be destroyed by the d'tor of FilterModule ConnectionQueue<Packet*> queue1(10); TestQueue<IpfixRecord*> tqueue; PacketAggregator agg(1); Rules* rules = createRules(); agg.buildAggregator(rules, 0, 0, 16); queue1.connectTo(&agg); agg.connectTo(&tqueue); agg.start(); queue1.start(); struct timeval starttime; REQUIRE(gettimeofday(&starttime, 0) == 0); sendPacketsTo(&queue1, numPackets); // check that at least one record was received IpfixRecord* rec; ASSERT(tqueue.pop(1000, &rec), "received timeout when should have received flow!"); struct timeval stoptime; REQUIRE(gettimeofday(&stoptime, 0) == 0); struct timeval difftime; REQUIRE(timeval_subtract(&difftime, &stoptime, &starttime) == 0); printf("Aggregator: needed time for processing %d packets: %d.%06d seconds\n", numPackets, (int)difftime.tv_sec, (int)difftime.tv_usec); queue1.shutdown(); agg.shutdown(); return PASSED; }