int main() { struct queue q; int i, j, k; queue_init (&q, sizeof(int), 5); i = 1; queue_push(&q, &i); i = 2; queue_push(&q, &i); i = 3; queue_push(&q, &i); j = *(int*)queue_front(&q); k = *(int*)queue_back(&q); printf ("%d, %d\n", j, k); queue_pop(&q); j = *(int*)queue_front(&q); k = *(int*)queue_back(&q); printf ("%d, %d\n", j, k); queue_pop(&q); queue_pop(&q); i = 11; queue_push(&q, &i); i = 12; queue_push(&q, &i); i = 13; queue_push(&q, &i); i = 14; queue_push(&q, &i); i = 15; queue_push(&q, &i); i = 16; queue_push(&q, &i); j = *(int*)queue_front(&q); k = *(int*)queue_back(&q); printf ("%d, %d\n", j, k); while (!queue_empty(&q)) { int s = *(int*)queue_front(&q); queue_pop(&q); printf ("%d\n", s); } return 0; }
int main() { // initialize queue_t testQ; queue_init(&testQ); // add some items queue_enqueue(&testQ, "item 1"); queue_enqueue(&testQ, "item 2"); queue_enqueue(&testQ, "item 3"); // print the queue queue_print(&testQ); // dequeue queue_dequeue(&testQ); // print the queue printf("After dequeueing once:\n"); queue_print(&testQ); printf("The size of the queue: %d\n", queue_size(&testQ)); // the front of the queue printf("The front of the queue: %s\n", (char *)queue_front(&testQ)); // the back of the queue printf("The back of the queue: %s\n", (char *)queue_back(&testQ)); // add some more items queue_enqueue(&testQ, "item4"); queue_enqueue(&testQ, "item5"); printf("After queueing twice more:\n"); queue_print(&testQ); // free up the queue's memory queue_destroy(&testQ); return 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()) {} }
/// @brief Main function to test the queue structure /// /// @return 0 if all went ok, 1 otherwise int main(void) { queue* s = NULL; int count = 100000; printf("\033[33m > Starting queue test\033[37m :\n\n"); // Creating queue printf("[ \033[32mCreating\033[37m queue ..\n"); s = queue_create(); if (!s) return 1; printf("Queue correctly created ] \n\n"); printf("Is the queue empty ? > %s\n", (queue_empty(s) ? "yes" : "no")); printf("Queue size : %i\n\n", queue_size(s)); // Pushing / Poping printf("[ \033[32mPushing\033[37m %i elements in the queue ..\n\n", count); for (int i = 0; i < count; i++) queue_push(s, i); printf("Is the queue empty ? > %s\n", (queue_empty(s) ? "yes" : "no")); printf("Queue size : %i\n\n", queue_size(s)); printf("[ \033[32mPoping\033[37m %i elements from the queue ..\n\n", count); for (int i = 0; i < count; i++) queue_pop(s); printf("Is the queue empty ? > %s\n", (queue_empty(s) ? "yes" : "no")); printf("Queue size : %i\n\n", queue_size(s)); printf("[ \033[32mPushing\033[37m 100000 elements in the queue ..\n\n"); for (int i = 0; i < count; i++) queue_push(s, i); printf("Is the queue empty ? > %s\n", (queue_empty(s) ? "yes" : "no")); printf("Queue size : %i\n\n", queue_size(s)); printf("[ \033[32mClearing\033[37m the queue ..\n\n"); queue_clear(s, NULL); printf("Is the queue empty ? > %s\n", (queue_empty(s) ? "yes" : "no")); printf("Queue size : %i\n\n", queue_size(s)); printf("[ \033[32mPushing\033[37m 1, 2, 3, 4, 5 in the queue ..\n\n"); queue_push(s, 1); queue_push(s, 2); queue_push(s, 3); queue_push(s, 4); queue_push(s, 5); printf("\033[32mFront\033[37m element is : %i\n", queue_front(s)); printf("\033[32mBack\033[37m element is : %i\n\n", queue_back(s)); printf("\033[32mVisiting\033[37m the queue ..\n"); queue_visit(s, visitor, NULL); printf("\n[ \033[32mDeleting\033[37m the queue..\n\n"); queue_delete(s, NULL); printf("Is the queue empty ? > %s\n", (queue_empty(s) ? "yes" : "no")); printf("Queue size : %i\n\n", queue_size(s)); return 0; }