-
Notifications
You must be signed in to change notification settings - Fork 4
/
TestUdpIpEthBypassTxPerf.bsv
161 lines (136 loc) · 5.32 KB
/
TestUdpIpEthBypassTxPerf.bsv
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
import Ports :: *;
import FIFOF :: *;
import GetPut :: *;
import Connectable :: *;
import Randomizable :: *;
import ClientServer :: *;
import EthUtils :: *;
import MacLayer :: *;
import EthernetTypes :: *;
import TestUtils :: *;
import UdpIpEthBypassCmacRxTx :: *;
import SemiFifo :: *;
import AxiStreamTypes :: *;
typedef 32 CYCLE_COUNT_WIDTH;
typedef 16 CASE_COUNT_WIDTH;
typedef 100000 MAX_CYCLE_NUM;
typedef 1000 TEST_CASE_NUM;
typedef 32'h7F000001 DUT_IP_ADDR;
typedef 48'hd89c679c4829 DUT_MAC_ADDR;
typedef 32'h00000000 DUT_NET_MASK;
typedef 32'h00000000 DUT_GATE_WAY;
typedef 16 BEAT_COUNT_WIDTH;
typedef 32 TEST_PKT_BEAT_NUM;
(* synthesize *)
module mkTestUdpIpEthBypassTxPerf();
Integer testCaseNum = valueOf(TEST_CASE_NUM);
Integer maxCycleNum = valueOf(MAX_CYCLE_NUM);
Integer pktBeatNum = valueOf(TEST_PKT_BEAT_NUM);
Bool isSelectBypassChannel = False;
// Common Signals
Reg#(Bool) isInit <- mkReg(False);
Reg#(Bit#(CYCLE_COUNT_WIDTH)) cycleCounter <- mkReg(0);
Reg#(Bit#(BEAT_COUNT_WIDTH)) inputBeatCounter <- mkReg(0);
Reg#(Bit#(CASE_COUNT_WIDTH)) inputPktCounter <- mkReg(0);
Reg#(Bit#(CASE_COUNT_WIDTH)) outputPktCounter <- mkReg(0);
Reg#(Bit#(CYCLE_COUNT_WIDTH)) inputStartCycle <- mkRegU;
Reg#(Bit#(CYCLE_COUNT_WIDTH)) inputEndCycle <- mkRegU;
Reg#(Bit#(CYCLE_COUNT_WIDTH)) outputStartCycle <- mkRegU;
Reg#(Bit#(CYCLE_COUNT_WIDTH)) outputEndCycle <- mkRegU;
Reg#(Bool) isRecvFirstBeat <- mkReg(False);
// DUT
let udpConfigVal = UdpConfig {
macAddr: fromInteger(valueOf(DUT_MAC_ADDR)),
ipAddr: fromInteger(valueOf(DUT_IP_ADDR)),
netMask: fromInteger(valueOf(DUT_NET_MASK)),
gateWay: fromInteger(valueOf(DUT_GATE_WAY))
};
let udpIpEthBypassRxTx <- mkGenericUdpIpEthBypassRxTx(`IS_SUPPORT_RDMA);
// Initialize Testbench
rule initTest if (!isInit);
udpIpEthBypassRxTx.udpConfig.put(udpConfigVal);
isInit <= True;
endrule
// Count Cycle Number
rule doCycleCount if (isInit);
cycleCounter <= cycleCounter + 1;
$display("\nCycle %d ----------------------------------------", cycleCounter);
immAssert(
cycleCounter < fromInteger(maxCycleNum),
"Testbench timeout assertion @ mkTestPfcUdpIpArpEthRxTx",
$format("Cycle number overflow %d", maxCycleNum)
);
endrule
// Tx Channel
rule sendUdpIpMetaData if (isInit);
let udpIpMetaData = UdpIpMetaData {
dataLen: fromInteger(valueOf(TEST_PKT_BEAT_NUM)) * fromInteger(valueOf(DATA_BUS_BYTE_WIDTH)),
ipAddr: fromInteger(valueOf(DUT_IP_ADDR)),
ipDscp: 0,
ipEcn: 0,
dstPort: fromInteger(valueOf(UDP_PORT_RDMA)),
srcPort: fromInteger(valueOf(UDP_PORT_RDMA))
};
if (!isSelectBypassChannel) begin
udpIpEthBypassRxTx.udpIpMetaDataTxIn.put(udpIpMetaData);
end
$display("Testbench: send UdpIpMetaData to DUT");
endrule
rule sendMacMetaData if (isInit);
let macMetaData = MacMetaData {
macAddr: fromInteger(valueOf(DUT_MAC_ADDR)),
ethType: fromInteger(valueOf(ETH_TYPE_IP))
};
udpIpEthBypassRxTx.macMetaDataTxIn.put(
MacMetaDataWithBypassTag {
macMetaData: macMetaData,
isBypass: isSelectBypassChannel
}
);
$display("Testbench: send MacMetaData to DUT");
endrule
rule sendDataStream if (isInit && inputPktCounter < fromInteger(testCaseNum));
let dataStream = DataStream {
data: ?,
byteEn: setAllBits,
isFirst: inputBeatCounter == 0,
isLast: inputBeatCounter == (fromInteger(pktBeatNum) - 1)
};
udpIpEthBypassRxTx.dataStreamTxIn.put(dataStream);
if (dataStream.isLast) begin
inputPktCounter <= inputPktCounter + 1;
inputBeatCounter <= 0;
if (inputPktCounter == fromInteger(testCaseNum) - 1) begin
inputEndCycle <= cycleCounter;
end
end
else begin
inputBeatCounter <= inputBeatCounter + 1;
end
if (inputPktCounter == 0 && inputBeatCounter == 0) begin
inputStartCycle <= cycleCounter;
end
$display("Testbench: Sends %d DataStream of %d testcase", inputBeatCounter, inputPktCounter);
endrule
rule recvOutputData;
let axiStream = udpIpEthBypassRxTx.axiStreamTxOut.first;
udpIpEthBypassRxTx.axiStreamTxOut.deq;
if (axiStream.tLast) begin
outputPktCounter <= outputPktCounter + 1;
if (outputPktCounter == fromInteger(testCaseNum) - 1) begin
outputEndCycle <= cycleCounter;
end
end
if (!isRecvFirstBeat) begin
outputStartCycle <= cycleCounter;
isRecvFirstBeat <= True;
end
$display("Testbench: recv one AXI-Stream Beat of %d testcase", outputPktCounter);
endrule
rule finishTest if (outputPktCounter == fromInteger(testCaseNum));
$display("Testbench: mkUdpIpEthBypassRxTx pass all %5d testcases", testCaseNum);
$display("Duration of send input data: %d", inputEndCycle - inputStartCycle + 1);
$display("Duration of recv output data: %d", outputEndCycle - outputStartCycle + 1);
$finish;
endrule
endmodule