float qLeftX[3] = {185.0f, 385.0f, 585.0f}; float qRightX[3] = {215.0f, 415.0f, 615.0f}; float timePosX = 600.0; float timePosY = 585.0f; char const * tempChar; char hourChar[4]; char minuteChar[4]; char commaChar = ','; char colonChar = ':'; char qtyChar[4]; char ppsChar[4]; char qQtyChar[4]; struct v3 { float x; float y; float z; }; enum Mode { simplePriority, weightedRoundRobin }; Mode mode; v3 priorityColor[3]; string tempStr; v3 roomColor[5]; vector< vector<Jadwal> > jadwalList; float lastFrameTime = 0; float deltaPacketTime = 0; float elapsedTime = 0; int incomingPacketPerSecond = 0; int processedPacketPerSecond = 0; int rejectedPacketPerSecond = 0; int roomPacketPerSecond[5]; int day = 0; int hour = 0; int minute = 0; const int minutesPerWeek = 10080; const int minutesPerDay = 1440; const int minutesPerHour = 60; const int hoursPerDay = 24; float currentTime = 0; int nowFastForward = 0; int fastForward = 30; int priority[5]; float sizeScale = 0.75;
Universita Sumatera Utara
queue<Packet> packetQ; PacketQueue q; PacketQueue qList[3]; int qListQty = 3; int qQty[3]; int packetPerSecond = 200; int packetProcessedPerSecond = 200; int robinToken = 0; int maxRobinToken = 90; // priorityDequeue mengambil void priorityDequeue() { Packet packet; bool dequeued = false; if (mode == simplePriority) { // Prioritas Berbasis Kelas // Setiap antrian memiliki kelas: 1, 2, dan 3, dimana kelas 3 akan diproses // paling pertama. Jika kelas 3 kosong, maka proses kelas 2. // Jika kelas 2 kosong, maka proses kelas 1 dequeued = qList[2].dequeu(packet); if (!dequeued) { dequeued = qList[1].dequeu(packet); } if (!dequeued) { dequeued = qList[0].dequeu(packet); } } else if (mode == weightedRoundRobin) { // Weighted Round Robin // Setiap antrian memiliki waktu tertentu untuk diproses. // Pada saat waktu itu, hanya antrian x yang dapat diproses. // Jika antrian kosong, maka pemrosesan tidak berjalan if (robinToken < 45) { dequeued = qList[2].dequeu(packet); if (!dequeued) { dequeued = qList[1].dequeu(packet); if (!dequeued) { dequeued = qList[0].dequeu(packet); } } } else if (robinToken >= 45 && robinToken < 75) { dequeued = qList[1].dequeu(packet); if (!dequeued) { dequeued = qList[2].dequeu(packet); if (!dequeued) { dequeued = qList[0].dequeu(packet); } } } else { dequeued = qList[0].dequeu(packet); if (!dequeued) { dequeued = qList[2].dequeu(packet); if (!dequeued) { dequeued = qList[1].dequeu(packet); } } } robinToken = (robinToken + 1) % 90; }
Universita Sumatera Utara
// menambah jumlah paket yang masuk sesuai dengan owner dari paket tersebut if (dequeued) { processedPacketPerSecond++; roomPacketPerSecond[packet.owner]++; } } void priorityQueue(Packet packet) { bool queued = qList[priority[packet.owner]].enqueue(packet); if (queued) { rejectedPacketPerSecond++; } } void generateRandomPacket() { Packet packet; packet.owner = rand() % 5; //q.enqueue(packet); priorityQueue(packet); } void processPacketQueue() { if (deltaPacketTime > 0.5f) { int packetProcessed = deltaPacketTime * packetProcessedPerSecond; for (int i = 0; i < packetProcessed; i++) { if (rand() % 10 < 5) { priorityDequeue(); } } } } void checkSchedule() { Jadwal jadwal; vector<Jadwal> temp; for (int i = 0; i < jadwalList.size(); i++) { temp = jadwalList.at(i); for (int j = 0; j < temp.size(); j++) { jadwal = temp.at(j); if (jadwal.day == day && hour >= jadwal.startHour && hour <= jadwal.endHour) { priority[i] = jadwal.priority; break; } else { priority[i] = 1; } } } } void updateTime() { if (lastFrameTime == 0) { lastFrameTime = glutGet(GLUT_ELAPSED_TIME); } int now = glutGet(GLUT_ELAPSED_TIME); elapsedTime = ((now - lastFrameTime) *1.0 / 1000.0f); lastFrameTime = now; nowFastForward = now * fastForward; minute = (int)((nowFastForward*1.0f)/1000.0f); hour = minute / minutesPerHour; day = minute / minutesPerDay; if (minute > minutesPerWeek) {