-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFIFO.cc
57 lines (48 loc) · 1.42 KB
/
FIFO.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <random>
#include "pifo_pipeline_stage.h"
#include "pifo_pipeline.h"
int main() {
try {
// Random number generation
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<int> ele_dis(1, 20);
// Traffic generation
PIFOPacket test_packet;
// Single PIFO pipeline stage consisting of
// 1 priority and queue
// (every PIFO pipeline stage has 1 calendar queue)
PIFOPipelineStage pifo1(1,
"ptr",
{{666, {Operation::TRANSMIT, {}}},},
[] (const auto & x) {if (x("ptr")==666){return x("time");}
int y = 0; return y;});
PIFOPipeline FIFO_pipeline({pifo1,});
PIFOPipeline mesh=FIFO_pipeline;
for (uint32_t i = 0; i < 500; i++) {
// enqueue victim packets
if(ele_dis(gen) == 1){
for(uint32_t j = 0; j < 5; j++){
test_packet("class") = 1;
test_packet("time") = (int) i;
test_packet("ptr") = 666;
mesh.enq(0, QueueType::PRIORITY_QUEUE, 0, test_packet, i);
}
}
// enqueue ping packets
if(i % 4 == 0){
test_packet("class") = 2;
test_packet("time") = (int) i;
test_packet("ptr") = 666;
mesh.enq(0, QueueType::PRIORITY_QUEUE, 0, test_packet, i);
}
//dequeue
auto result = mesh.deq(0, QueueType::PRIORITY_QUEUE, 0, i);
std::cout << "tick: " << i << ", " << result << std::endl;
}
} catch (const std::exception & e) {
std::cerr << "Caught exception in main " << std::endl << e.what() << std::endl;
return EXIT_FAILURE;
}
}