-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmess_queue.cc
More file actions
108 lines (93 loc) · 2.96 KB
/
Copy pathmess_queue.cc
File metadata and controls
108 lines (93 loc) · 2.96 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "mess_queue.h"
#include "sim_foundation.h"
#include <string>
#include <iostream>
#include <strstream>
#include <unistd.h>
//changed at 2020-5-23
ofstream logfile("popnet.log");
bool operator<(const mess_event & a, const mess_event & b) {
return a.event_start() < b.event_start();
}
bool operator>(const mess_event&a,const mess_event&b)
{
return a.event_start()>b.event_start();
}
mess_queue * mess_queue::m_pointer_ = nullptr;
mess_queue::mess_queue(time_type start_time):
current_time_(0),
last_time_(0),
mess_counter_(0),
m_q_(),
total_finished_(0)
{
current_time_ = start_time;
m_pointer_ = this;
//changed at 2020-5-8
//add_message(mess_event(0, ROUTER_));
add_message(mess_event(TIME_0, ROUTER_));
}
string mess_queue:: mess_error_ =
string("This message type is not supported.\n");
//commented at 2020-3
//主循环,不断循环处理消息
void mess_queue::simulator() {
//changed at 2020-5-23
//static uint64_t wireMsgCnt=0,creditMsgCnt=0;
time_type report_t = 0;
long total_incoming = 0;
//修改此循环
//when mess queue is not empty and simulation deadline has not reach
while(m_q_.size() > 0 && (current_time_ <= (configuration
::ap().sim_length()))) {
//changed at 2021-10-26
//mess_event current_message = * get_message();
mess_event current_message=get_message();
//changed at 2020-5-23
//输出日志
logfile<<current_message;
if(current_message.event_type()==WIRE_||current_message.event_type()==CREDIT_){
logfile<<"\tFrom Router "<<current_message.src()
<<" to Router "<<current_message.des()
<<" Port "<<current_message.pc()
<<" Virtual Channel "<<current_message.vc()<<endl;
}
remove_top_message();
//保证当前时间小于或等于事件开始时间
Sassert(static_cast<bool>(current_time_ <= ((current_message.
event_start()) + S_ELPS_)));
//if(current_time_>current_message.event_start()+S_ELPS_)continue;
current_time_ = current_message.event_start();
if(current_time_ > report_t) {
cout<<"Current time: "<<current_time_<<" Incoming packets"
<<total_incoming<<" Finished packets"<<total_finished_<<endl;
//changed at 2020-5-23
//cout<<"Wire Message Count: "<<wireMsgCnt<<" Credit Message Count: "<<creditMsgCnt<<endl;
sim_foundation::wsf().simulation_results();
report_t += REPORT_PERIOD_;
}
switch(current_message.event_type()) {
case EVG_ ://读取轨迹文件的下一条记录
//TODO: 改为读取外部输入
sim_foundation::wsf().receive_EVG_message(current_message);
total_incoming ++;
break;
case ROUTER_ :
sim_foundation::wsf().receive_ROUTER_message(current_message);
break;
case WIRE_ :
sim_foundation::wsf().receive_WIRE_message(current_message);
//changed at 2020-5-23
//wireMsgCnt++;
break;
case CREDIT_ :
sim_foundation::wsf().receive_CREDIT_message(current_message);
//changed at 2020-5-23
//creditMsgCnt++;
break;
default:
throw pro_error(mess_error_);
break;
}
}
}