Пример #1
0
/**
 * 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();
}
TEST(push_pop, Queue)
{
  Queue<int> queue2(10);
  queue2.push(10);
  queue2.push(15);
  queue2.push(20);
  queue2.push(25);

  CHECK_EQUAL(10, queue2.pop());
  CHECK_EQUAL(15, queue2.pop());
}
Пример #3
0
//=============================================================================
//==  Function to generate Poisson customers                                 ==
//==   - Random split to queue1() and queue2()                               ==
//=============================================================================
void generate(double lambda, double mu)
{
  double   interarrival_time;    // Interarrival time to next send
  double   service_time;         // Service time for this customer
  int      select_queue = 1;         // if 1 go to queue1

  create("generate");

  // Loop forever to create customers
  while(1)
  {
    // Pull an interarrival time and hold for it
    interarrival_time = exponential(1.0 / lambda);
    hold(interarrival_time);

    // Pull a service time
    //service_time = exponential(1.0 / mu);
    service_time = mu;

    // Send the customer to a randomly selected queue
    if (select_queue == 1)
    {
      queue1(service_time, clock);
      select_queue++;
    }
    else if (select_queue == 2)
    {
      queue2(service_time, clock);
      select_queue++;
    }
    else if (select_queue == 3)
    {
      queue3(service_time, clock);
      select_queue++;
    }
    else if (select_queue == 4)
    {
      queue4(service_time, clock);
      select_queue++;
    }
    else
    {
      queue5(service_time, clock);
      select_queue = 1;
    }
  }
}
Пример #4
0
void PriorityQueue_test::testQueue()
{
    QList<Node*> list;
    QHash<QByteArray, Node*> dict;

    KOfficeFilter::PriorityQueue<Node> queue;

    srand(time(0));
    for (int i = 0; i < 12; ++i) {
        Node *n = new Node(rand() % 20);
        list.append(n);
        queue.insert(n);
        Node *n2 = new Node(*n);
        dict.insert(keys[i], n2);
    }

    kDebug() << "##### Queue 1:";
    queue.dump();
    QCOMPARE((int) queue.count(), list.count());
    QCOMPARE(queue.isEmpty(), false);
    QCOMPARE(queue.extractMinimum()->index(), 0);


    kDebug() << "##### Queue 2:";
    KOfficeFilter::PriorityQueue<Node> queue2(dict);
    //queue2.dump();

    Node *n = list.at(6);
    kDebug() << "##### Decreasing node:" << n->key() << " at" << n->index();
    n->setKey(2);
    queue.keyDecreased(n);
    queue.dump();

    n = list.at(2);
    kDebug() << "##### Decreasing node:" << n->key() << " at" << n->index();
    n->setKey(0);
    queue.keyDecreased(n);
    queue.dump();

    n = queue.extractMinimum();
    while (n) {
        queue.dump();
        n = queue.extractMinimum();
    }
}
Пример #5
0
int main(int /*argc*/, char ** /*argv*/)
{
    Q3PtrList<Node> list;
    list.setAutoDelete(true);
    Q3AsciiDict<Node> dict;

    KOffice::PriorityQueue<Node> queue;

    srand(time(0));
    for (int i = 0; i < 12; ++i) {
        Node *n = new Node(rand() % 20);
        list.append(n);
        queue.insert(n);
        // Check whether the AsciiDict CTOR is okay
        Node *n2 = new Node(*n);
        dict.insert(keys[ i ], n2);
    }

    kDebug() << "##### Queue 1:";
    queue.dump();

    kDebug() << "##### Queue 2:";
    KOffice::PriorityQueue<Node> queue2(dict);
    queue2.dump();

    Node *n = list.at(6);
    kDebug() << "##### Decreasing node:" << n->key() << " at" << n->index();
    n->setKey(2);
    queue.keyDecreased(n);
    queue.dump();

    n = list.at(2);
    kDebug() << "##### Decreasing node:" << n->key() << " at" << n->index();
    n->setKey(0);
    queue.keyDecreased(n);
    queue.dump();

    n = queue.extractMinimum();
    while (n) {
        queue.dump();
        n = queue.extractMinimum();
    }
    return 0;
}
Пример #6
0
int main(int argc, char **argv) {
    EventList eventlist;
    eventlist.setEndtime(timeFromSec(5000));
    Clock c(timeFromSec(50/100.), eventlist);
    int algo = UNCOUPLED;
    double epsilon = 1;
    int crt = 2;

    if (argc>1) {
        if (!strcmp(argv[1],"UNCOUPLED"))
            algo = UNCOUPLED;
        else if (!strcmp(argv[1],"COUPLED_INC"))
            algo = COUPLED_INC;
        else if (!strcmp(argv[1],"FULLY_COUPLED"))
            algo = FULLY_COUPLED;
        else if (!strcmp(argv[1],"COUPLED_TCP"))
            algo = COUPLED_TCP;
        else if (!strcmp(argv[1],"COUPLED_EPSILON")) {
            algo = COUPLED_EPSILON;
            if (argc>2) {
                epsilon = atof(argv[2]);
                crt++;
                printf("Using epsilon %f\n",epsilon);
            }
        }
        else
            exit_error(argv[0]);
    }
    linkspeed_bps SERVICE1 = speedFromPktps(400);
    linkspeed_bps SERVICE2;
    if (argc>crt)
        SERVICE2 = speedFromPktps(atoi(argv[crt++]));
    else
        SERVICE2 = speedFromPktps(400);

    simtime_picosec RTT1=timeFromMs(100);
    simtime_picosec RTT2;
    if (argc>crt)
        RTT2 = timeFromMs(atoi(argv[crt]));
    else
        RTT2 = timeFromMs(100);

    mem_b BUFFER1=memFromPkt(RANDOM_BUFFER+timeAsSec(RTT1)*speedAsPktps(SERVICE1));//NUMFLOWS * targetwnd);
    mem_b BUFFER2=memFromPkt(RANDOM_BUFFER+timeAsSec(RTT2)*speedAsPktps(SERVICE2));//NUMFLOWS * targetwnd);

    srand(time(NULL));

    // prepare the loggers
    stringstream filename(ios_base::out);
    filename << "../data/logout." << speedAsPktps(SERVICE2) << "pktps." <<timeAsMs(RTT2) << "ms."<< rand();
    cout << "Outputting to " << filename.str() << endl;
    Logfile logfile(filename.str(),eventlist);

    logfile.setStartTime(timeFromSec(0.5));
    QueueLoggerSimple logQueue = QueueLoggerSimple();
    logfile.addLogger(logQueue);
    //	QueueLoggerSimple logPQueue1 = QueueLoggerSimple(); logfile.addLogger(logPQueue1);
    //QueueLoggerSimple logPQueue3 = QueueLoggerSimple(); logfile.addLogger(logPQueue3);
    QueueLoggerSimple logPQueue = QueueLoggerSimple();
    logfile.addLogger(logPQueue);
    MultipathTcpLoggerSimple mlogger = MultipathTcpLoggerSimple();
    logfile.addLogger(mlogger);

    //TrafficLoggerSimple logger;
    //logfile.addLogger(logger);
    SinkLoggerSampling sinkLogger = SinkLoggerSampling(timeFromMs(1000),eventlist);

    logfile.addLogger(sinkLogger);


    QueueLoggerSampling qs1 = QueueLoggerSampling(timeFromMs(1000),eventlist);
    logfile.addLogger(qs1);
    QueueLoggerSampling qs2 = QueueLoggerSampling(timeFromMs(1000),eventlist);
    logfile.addLogger(qs2);

    TcpLoggerSimple* logTcp = NULL;

    logTcp = new TcpLoggerSimple();
    logfile.addLogger(*logTcp);

    // Build the network
    Pipe pipe1(RTT1, eventlist);
    pipe1.setName("pipe1");
    logfile.writeName(pipe1);
    Pipe pipe2(RTT2, eventlist);
    pipe2.setName("pipe2");
    logfile.writeName(pipe2);
    Pipe pipe_back(timeFromMs(.1), eventlist);
    pipe_back.setName("pipe_back");
    logfile.writeName(pipe_back);

    RandomQueue queue1(SERVICE1, BUFFER1, eventlist,&qs1,memFromPkt(RANDOM_BUFFER));
    queue1.setName("Queue1");
    logfile.writeName(queue1);

    RandomQueue queue2(SERVICE2, BUFFER2, eventlist,&qs2,memFromPkt(RANDOM_BUFFER));
    queue2.setName("Queue2");
    logfile.writeName(queue2);
    Queue pqueue2(SERVICE2*2, memFromPkt(FEEDER_BUFFER), eventlist,NULL);
    pqueue2.setName("PQueue2");
    logfile.writeName(pqueue2);
    Queue pqueue3(SERVICE1*2, memFromPkt(FEEDER_BUFFER), eventlist,NULL);
    pqueue3.setName("PQueue3");
    logfile.writeName(pqueue3);
    Queue pqueue4(SERVICE2*2, memFromPkt(FEEDER_BUFFER), eventlist,NULL);
    pqueue4.setName("PQueue4");
    logfile.writeName(pqueue4);

    Queue* pqueue;

    Queue queue_back(max(SERVICE1,SERVICE2)*4, memFromPkt(1000), eventlist,NULL);
    queue_back.setName("queue_back");
    logfile.writeName(queue_back);

    TcpRtxTimerScanner tcpRtxScanner(timeFromMs(10), eventlist);

    //TCP flows on path 1
    TcpSrc* tcpSrc;
    TcpSink* tcpSnk;
    route_t* routeout;
    route_t* routein;
    double extrastarttime;

    for (int i=0; i<TCP_1; i++) {
        tcpSrc = new TcpSrc(NULL,NULL,eventlist);
        tcpSrc->setName("Tcp1");
        logfile.writeName(*tcpSrc);
        tcpSnk = new TcpSink();
        tcpSnk->setName("Tcp1");
        logfile.writeName(*tcpSnk);

        tcpRtxScanner.registerTcp(*tcpSrc);

        // tell it the route
        pqueue = new Queue(SERVICE1*2, memFromPkt(FEEDER_BUFFER), eventlist,NULL);
        pqueue->setName("PQueue1_"+ntoa(i));
        logfile.writeName(*pqueue);

        routeout = new route_t();
        routeout->push_back(pqueue);
        routeout->push_back(&queue1);
        routeout->push_back(&pipe1);
        routeout->push_back(tcpSnk);

        routein  = new route_t();
        routein->push_back(tcpSrc);

        extrastarttime = drand()*50;
        tcpSrc->connect(*routeout,*routein,*tcpSnk,timeFromMs(extrastarttime));
        sinkLogger.monitorSink(tcpSnk);
    }

    //TCP flow on path 2
    for (int i=0; i<TCP_2; i++) {
        tcpSrc = new TcpSrc(NULL,NULL,eventlist);
        tcpSrc->setName("Tcp2");
        logfile.writeName(*tcpSrc);
        tcpSnk = new TcpSink();
        tcpSnk->setName("Tcp2");
        logfile.writeName(*tcpSnk);

        tcpRtxScanner.registerTcp(*tcpSrc);

        pqueue = new Queue(SERVICE2*2, memFromPkt(FEEDER_BUFFER), eventlist,NULL);
        pqueue->setName("PQueue2_"+ntoa(i));
        logfile.writeName(*pqueue);

        // tell it the route
        routeout = new route_t();
        routeout->push_back(pqueue);
        routeout->push_back(&queue2);
        routeout->push_back(&pipe2);
        routeout->push_back(tcpSnk);

        routein  = new route_t(); //routein->push_back(&queue_back); routein->push_back(&pipe_back);
        routein->push_back(tcpSrc);
        extrastarttime = 50*drand();
        tcpSrc->connect(*routeout,*routein,*tcpSnk,timeFromMs(extrastarttime));
        sinkLogger.monitorSink(tcpSnk);
    }

    MultipathTcpSrc* mtcp;
    if (algo==COUPLED_EPSILON)
        mtcp = new MultipathTcpSrc(algo,eventlist,&mlogger,epsilon);
    else
        mtcp = new MultipathTcpSrc(algo,eventlist,&mlogger);

    //MTCP flow 1
    tcpSrc = new TcpSrc(NULL,NULL,eventlist);
    tcpSrc->setName("Subflow1");
    logfile.writeName(*tcpSrc);
    tcpSnk = new TcpSink();
    tcpSnk->setName("Subflow1");
    logfile.writeName(*tcpSnk);

    tcpRtxScanner.registerTcp(*tcpSrc);

    // tell it the route
    routeout = new route_t();
    routeout->push_back(&pqueue3);
    routeout->push_back(&queue1);
    routeout->push_back(&pipe1);
    routeout->push_back(tcpSnk);

    routein  = new route_t();
    //routein->push_back(&queue_back); routein->push_back(&pipe_back);
    routein->push_back(tcpSrc);
    extrastarttime = 50*drand();

    //join multipath connection
    mtcp->addSubflow(tcpSrc);

    tcpSrc->connect(*routeout,*routein,*tcpSnk,timeFromMs(extrastarttime));
    sinkLogger.monitorSink(tcpSnk);

    //MTCP flow 2
    tcpSrc = new TcpSrc(NULL,NULL,eventlist);
    tcpSrc->setName("Subflow2");
    logfile.writeName(*tcpSrc);
    tcpSnk = new TcpSink();
    tcpSnk->setName("Subflow2");
    logfile.writeName(*tcpSnk);
    tcpRtxScanner.registerTcp(*tcpSrc);

    // tell it the route
    routeout = new route_t();
    routeout->push_back(&pqueue4);
    routeout->push_back(&queue2);
    routeout->push_back(&pipe2);
    routeout->push_back(tcpSnk);

    routein  = new route_t();
    //routein->push_back(&queue_back); routein->push_back(&pipe_back);
    routein->push_back(tcpSrc);
    extrastarttime = 50*drand();

    //join multipath connection
    mtcp->addSubflow(tcpSrc);

    tcpSrc->connect(*routeout,*routein,*tcpSnk,timeFromMs(extrastarttime));
    sinkLogger.monitorSink(tcpSnk);

    // Record the setup
    int pktsize = TcpPacket::DEFAULTDATASIZE;
    logfile.write("# pktsize="+ntoa(pktsize)+" bytes");
    logfile.write("# bottleneckrate1="+ntoa(speedAsPktps(SERVICE1))+" pkt/sec");
    logfile.write("# bottleneckrate2="+ntoa(speedAsPktps(SERVICE2))+" pkt/sec");
    logfile.write("# buffer1="+ntoa((double)(queue1._maxsize)/((double)pktsize))+" pkt");
    logfile.write("# buffer2="+ntoa((double)(queue2._maxsize)/((double)pktsize))+" pkt");
    double rtt = timeAsSec(RTT1);
    logfile.write("# rtt="+ntoa(rtt));
    rtt = timeAsSec(RTT2);
    logfile.write("# rtt="+ntoa(rtt));
    logfile.write("# numflows="+ntoa(NUMFLOWS));
    logfile.write("# targetwnd="+ntoa(targetwnd));

    // GO!
    while (eventlist.doNextEvent()) {}
}
//=============================================================================
//==  Function to generate Poisson customers                                 ==
//==   - Random split to queue1() and queue2()                               ==
//=============================================================================
void generate(double lambda, double mu)
{
  double   interarrival_time;    // Interarrival time to next send
  double   service_time;         // Service time for this customer
  double   rv;                   // Random Value
  int      queue_len[5];         // Number of customers in system
  int      ties[5];              // Tied queue values
  int      select_q;             // Queue Chosen
  int      short_val;            // Shortest Queue value
  int      num_ties;             // Number of ties
  int      i;                    // Iteration value

  create("generate");

  // Loop forever to create customers
  while(1)
  {
    // Pull an interarrival time and hold for it
    interarrival_time = exponential(1.0 / lambda);
    hold(interarrival_time);

    // Pull a service time
    //service_time = exponential(1.0 / mu);
    service_time = mu;

    // Get # customers in each system
    queue_len[0] = qlength(Server1) + num_busy(Server1);
    queue_len[1] = qlength(Server2) + num_busy(Server2);
    queue_len[2] = qlength(Server3) + num_busy(Server3);
    queue_len[3] = qlength(Server4) + num_busy(Server4);
    queue_len[4] = qlength(Server5) + num_busy(Server5);

    // Calculate shortest queue
    short_val = queue_len[0];
    for(i=1; i<5; i++)
    {
      if(queue_len[i] < short_val)
        short_val = queue_len[i];
    }

    // Determine ties
    num_ties = 0;
    for(i=0; i<5; i++)
    {
      if (short_val == queue_len[i])
      {
        select_q = i;
        ties[num_ties] = i;
        num_ties++;
      }
    }

    // Randomly select queue if tie occurs
    if(num_ties > 1)
    {
      rv = uniform(0.0,(double)num_ties);

      for(i=1; i<=num_ties; i++)
      {
        if(rv <= i)
        {
          select_q = ties[i-1];
          break;
        }
      }
    }

    // Send the customer to shortest queue
    if(select_q == 0)
      queue1(service_time, clock);
    else if(select_q == 1)
      queue2(service_time, clock);
    else if(select_q == 2)
      queue3(service_time, clock);
    else if(select_q == 3)
      queue4(service_time, clock);
    else
      queue5(service_time, clock);
  }
}
Пример #8
0
int main(int argc, char* argv)
{
	const int count = 100 * 10000;

	boost::asio::io_service ioService1;
	cr::network::AsyncQueue<int> queue1(ioService1);

	auto startTime = std::chrono::high_resolution_clock::now();
	std::thread t1([&]
	{
		boost::asio::io_service::work work(ioService1);
		queue1.asyncPush(1, std::bind(&push, std::ref(queue1), count, std::placeholders::_1));
		queue1.asyncPop(std::bind(&pop, std::ref(queue1), std::placeholders::_1, std::placeholders::_2));
		ioService1.run();
	});
	t1.join();
	//t2.join();
	auto topTime = std::chrono::high_resolution_clock::now();

	auto totalTime = std::chrono::duration_cast<std::chrono::microseconds>(topTime - startTime).count();
	std::cout << "microseonds: " << totalTime / 1000 << "\n"
		<< "message count: " << count << std::endl
		<< "speed :" << 1.0 * totalTime / count << "\n";

	boost::asio::io_service ioService2;
	boost::asio::io_service ioService3;
	cr::network::AsyncQueue<int, std::mutex> queue2(ioService2, ioService3);

	int count2 = count;
	for (int i = 0; i < 10; ++i)
	{
		boost::asio::spawn(ioService2, [&](boost::asio::yield_context yield)
		{
			boost::system::error_code ec;
			while (count2-- > 0)
			{
				queue2.asyncPush(1, yield[ec]);
			}
			queue2.getPushIoService().stop();
			queue2.getPopIoService().stop();
		});
	}

	boost::asio::spawn(ioService3, [&](boost::asio::yield_context yield)
	{
		boost::system::error_code ec;
		while (!ec)
		{
			int element = queue2.asyncPop(yield[ec]);
		}
	});

	auto startTime2 = std::chrono::high_resolution_clock::now();
	std::thread t2([&]
	{
		boost::asio::io_service::work work(ioService2);
		ioService2.run();
	});
	std::thread t3([&]
	{
		boost::asio::io_service::work work(ioService3);
		ioService3.run();
	});
	t2.join();
	t3.join();
	auto stopTime2 = std::chrono::high_resolution_clock::now();

	auto totalTime2 = std::chrono::duration_cast<std::chrono::microseconds>(stopTime2 - startTime2).count();
	std::cout << "microseonds: " << totalTime2 / 1000 << "\n"
		<< "message count: " << count << std::endl
		<< "speed :" << 1.0 * totalTime2 / count << "\n";

	boost::asio::io_service ioService4;
	cr::network::AsyncQueue<int, std::mutex> queue3(ioService4);
	boost::asio::spawn(ioService4, [&](boost::asio::yield_context yield)
	{
		boost::system::error_code ec;
		int element = 1;
		while (element != 0)
		{
			element = queue3.asyncPop(yield[ec]);
		}
		ioService4.stop();
	});
	auto startTime3 = std::chrono::high_resolution_clock::now();

	std::thread t4([&]
	{
		boost::asio::io_service::work work(ioService4);
		ioService4.run();
	});
	for (int i = 1; i < count; ++i)
	{
		queue3.push(i);
	}
	queue3.push(0);
	t4.join();

	auto stopTime3 = std::chrono::high_resolution_clock::now();
	auto totalTime3 = std::chrono::duration_cast<std::chrono::microseconds>(stopTime3 - startTime3).count();
	std::cout << "microseonds: " << totalTime3 / 1000 << "\n"
		<< "message count: " << count << std::endl
		<< "speed :" << 1.0 * totalTime3 / count << "\n";
}