-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiperf_udp.sv
203 lines (168 loc) · 5.05 KB
/
iperf_udp.sv
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// two gaps used in iperf, one gap to set IPD among packets, the other to set wait time between two streams of packets to avoid congestion
module iperfudp (
input clk,
input rst,
input initSeqNum,
(* anyseq *) input pktArrival,
input packetGap,
input receivedResponse,
output reg [31:0] counter, // comparator counter,
output wire timeOver,
output wire lastPkt
);
reg [31:0] PktTimer;
reg [31:0] pktCnt;
reg [3:0] iperfFsmState;
reg timeOverReg;
reg lastPktReg;
reg [7:0] wordCount;
reg [31:0] seqNumber;
reg [31:0] cycleCounter;
reg [31:0] waitCounter;
reg [31:0] pkgHeaderCount;
reg [31:0] packetGapCounter;
parameter pktNumber = 3,
senderIPD = 10,
totalCycles = 995,
//Other parameters:
pkgTotalWord = 1000,
headerWord = 40,
timeOverValue = 200,
WAIT_END = 100,
//state
IDLE = 0, //end of a sequence of packets, go back to IDLE
CONSTRUCT_HEADER = 1, //end of a packet, go back to CONSTRUCT_HEADER
HEADER = 2,
WRITE_PKG = 3,
WAIT_RESPONSE = 4,
PKG_GAP = 5;
/*
initial begin
assume(rst);
end
*/
//net connection
assign timeOver = timeOverReg;
assign lastPkt = lastPktReg;
//absolute timer
always @(posedge clk) begin
if(rst)begin
cycleCounter <= 0;
end
else begin
cycleCounter<=cycleCounter+1;
end
end
//packet counter
always @(posedge clk) begin
if(rst)
pktCnt <= 0;
else
if(pktArrival)
pktCnt <= pktCnt + 1;
else
pktCnt <= pktCnt;
end
//FSM
always @(posedge clk) begin
if(rst) begin
seqNumber <= initSeqNum;
packetGapCounter <= 0;
waitCounter <= 0;
end
else begin //!rst
case(iperfFsmState)
IDLE: begin
timeOverReg <= 0;
lastPktReg <= 0;
PktTimer <= cycleCounter;
wordCount <= 0;
iperfFsmState <= CONSTRUCT_HEADER;
end
CONSTRUCT_HEADER: begin
seqNumber <= seqNumber + 1;
iperfFsmState <= HEADER;
end
HEADER: begin
//header write
if(wordCount>headerWord) begin
iperfFsmState <= WRITE_PKG;
end
else begin
wordCount<=wordCount+1;
end
end
WRITE_PKG: begin
if (wordCount < pkgTotalWord) begin
wordCount <= wordCount + 1;
end
else //wordCount>=pkgTotalWord, finish transmitting one packet
//timeOut to avoid congestion, marked as the last packet, so we go to WAIT_RESPONSE state.
if(cycleCounter - PktTimer>timeOverValue) begin
timeOverReg <= 1;
lastPktReg <= 1;
if(receivedResponse) begin
iperfFsmState <= IDLE;
end
else begin
iperfFsmState <= WAIT_RESPONSE;
end
end
else begin
timeOverReg <= 0;
PktTimer <= cycleCounter - PktTimer;
if(packetGap != 0) begin
iperfFsmState <= PKG_GAP;
end
else begin
iperfFsmState <= IDLE;
end
end
end
end
WAIT_RESPONSE: begin
waitCounter <= waitCounter + 1;
if(waitCounter >= WAIT_END) begin
waitCounter <= 0;
iperfFsmState <= IDLE;
end
end
PKG_GAP: begin
if(packetGapCounter >= packetGap) begin
packetGapCounter <= 0;
iperfFsmState <= IDLE;
end
else begin
packetGapCounter <= packetGapCounter + 1;
end
end
default : begin
end
endcase
end
end
`ifdef FORMAL
always @(posedge clk) begin
if(!$initstate) begin
assume(rst == 0);
//packet time simulation
assume(IPDTimer < rangeMax);
if(pktArrival) assume(IPDTimer > rangeMin);
if(globalTimer == totalCycles )assume(pktCnt == pktNumber);
assume(pktCnt<=10000);
//-----//
//Invariant
assume(counter <= pktCnt); //-- not automatic
//assume(counter <= globalTimer / rangeMin); //-- not automatic
//-----//
// a property
if(globalTimer == totalCycles) assert(counter == 3);
end
else begin
assume(rst);
end
end
`endif
endmodule
/* Note: WRITE_PKG ---> wordCount>=totalCount ---> recordTime, if Time>threshold, then it is the last pkg, otherwise it is not the last pkg*/
/* timeOut to avoid congestion, so we go to WAIT_RESPONSE state. */