OpenCores
URL https://opencores.org/ocsvn/udp_ip_stack/udp_ip_stack/trunk

Subversion Repositories udp_ip_stack

[/] [udp_ip_stack/] [trunk/] [bench/] [vhdl/] [IPv4_TX_tb.vhd] - Blame information for rev 6

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 pjf
--------------------------------------------------------------------------------
2
-- Company: 
3
-- Engineer:
4
--
5
-- Create Date:   09:35:58 06/03/2011
6
-- Design Name:   
7
-- Module Name:   C:/Users/pjf/Documents/projects/fpga/xilinx/Network/ip1/IPv4_TX_tb.vhd
8
-- Project Name:  ip1
9
-- Target Device:  
10
-- Tool versions:  
11
-- Description:   
12
-- 
13
-- VHDL Test Bench Created by ISE for module: IPv4_TX
14
-- 
15
-- Dependencies:
16
-- 
17
-- Revision:
18
-- Revision 0.01 - File Created
19 6 pjf
-- Revision 0.02 - Added test for IP broadcast tx
20 2 pjf
-- Additional Comments:
21
--
22
-- Notes: 
23
-- This testbench has been automatically generated using types std_logic and
24
-- std_logic_vector for the ports of the unit under test.  Xilinx recommends
25
-- that these types always be used for the top-level I/O of a design in order
26
-- to guarantee that the testbench will bind correctly to the post-implementation 
27
-- simulation model.
28
--------------------------------------------------------------------------------
29
LIBRARY ieee;
30
USE ieee.std_logic_1164.ALL;
31
use IEEE.NUMERIC_STD.ALL;
32
use work.axi.all;
33
use work.ipv4_types.all;
34
use work.arp_types.all;
35
 
36
 
37
ENTITY IPv4_TX_tb IS
38
END IPv4_TX_tb;
39
 
40
ARCHITECTURE behavior OF IPv4_TX_tb IS
41
 
42
    -- Component Declaration for the Unit Under Test (UUT)
43
 
44
    COMPONENT IPv4_TX
45
    PORT(
46
                        -- IP Layer signals
47
                        ip_tx_start                             : in std_logic;
48
                        ip_tx                                           : in ipv4_tx_type;                                                              -- IP tx cxns
49
                        ip_tx_result                    : out std_logic_vector (1 downto 0);             -- tx status (changes during transmission)
50
                        ip_tx_data_out_ready    : out std_logic;                                                                        -- indicates IP TX is ready to take data
51
 
52
                        -- system signals
53
                        clk                                             : in  STD_LOGIC;                                                                        -- same clock used to clock mac data and ip data
54
                        reset                                   : in  STD_LOGIC;
55
                        our_ip_address          : in STD_LOGIC_VECTOR (31 downto 0);
56
                        our_mac_address                 : in std_logic_vector (47 downto 0);
57
                        -- ARP lookup signals
58
                        arp_req_req                             : out arp_req_req_type;
59
                        arp_req_rslt                    : in arp_req_rslt_type;
60
                        -- MAC layer TX signals
61
                        mac_tx_req                              : out std_logic;                                                                        -- indicates that ip wants access to channel (stays up for as long as tx)
62
                        mac_tx_granted                  : in std_logic;                                                                 -- indicates that access to channel has been granted            
63
                        mac_data_out_ready      : in std_logic;                                                                 -- indicates system ready to consume data
64
                        mac_data_out_valid      : out std_logic;                                                                -- indicates data out is valid
65 4 pjf
                        mac_data_out_first      : out std_logic;                                                                        -- with data out valid indicates the first byte of a frame
66 2 pjf
                        mac_data_out_last               : out std_logic;                                                                        -- with data out valid indicates the last byte of a frame
67
                        mac_data_out                    : out std_logic_vector (7 downto 0)              -- ethernet frame (from dst mac addr through to last byte of frame)      
68
        );
69
    END COMPONENT;
70
 
71
 
72
   --Inputs
73
   signal ip_tx_start : std_logic := '0';
74
   signal ip_tx : ipv4_tx_type;
75
   signal clk : std_logic := '0';
76
   signal reset : std_logic := '0';
77
   signal our_ip_address : std_logic_vector(31 downto 0) := (others => '0');
78
   signal our_mac_address : std_logic_vector(47 downto 0) := (others => '0');
79
   signal mac_tx_granted : std_logic := '0';
80
   signal mac_data_out_ready : std_logic := '0';
81
   signal arp_req_rslt : arp_req_rslt_type;
82
 
83
        --Outputs
84
        signal ip_tx_result : std_logic_vector (1 downto 0);                                             -- tx status (changes during transmission)
85
        signal ip_tx_data_out_ready     :  std_logic;                                                                   -- indicates IP TX is ready to take data
86
   signal mac_tx_req : std_logic;
87
   signal mac_data_out_valid : std_logic;
88
   signal mac_data_out_last : std_logic;
89 4 pjf
   signal mac_data_out_first : std_logic;
90 2 pjf
   signal mac_data_out : std_logic_vector(7 downto 0);
91
   signal arp_req_req : arp_req_req_type;
92
 
93
   -- Clock period definitions
94
   constant clk_period : time := 8 ns;
95
 
96
BEGIN
97
 
98
        -- Instantiate the Unit Under Test (UUT)
99
   uut: IPv4_TX PORT MAP (
100
          ip_tx_start => ip_tx_start,
101
          ip_tx => ip_tx,
102
          ip_tx_result => ip_tx_result,
103
          ip_tx_data_out_ready => ip_tx_data_out_ready,
104
          clk => clk,
105
          reset => reset,
106
          our_ip_address => our_ip_address,
107
          our_mac_address => our_mac_address,
108
          arp_req_req => arp_req_req,
109
          arp_req_rslt => arp_req_rslt,
110
          mac_tx_req => mac_tx_req,
111
          mac_tx_granted => mac_tx_granted,
112
          mac_data_out_ready => mac_data_out_ready,
113
          mac_data_out_valid => mac_data_out_valid,
114 4 pjf
                         mac_data_out_first => mac_data_out_first,
115 2 pjf
          mac_data_out_last => mac_data_out_last,
116
          mac_data_out => mac_data_out
117
        );
118
 
119
   -- Clock process definitions
120
   clk_process :process
121
   begin
122
                clk <= '0';
123
                wait for clk_period/2;
124
                clk <= '1';
125
                wait for clk_period/2;
126
   end process;
127
 
128
 
129
   -- Stimulus process
130
   stim_proc: process
131
   begin
132
                our_ip_address <= x"c0a80509";          -- 192.168.5.9
133
                our_mac_address <= x"002320212223";
134
                ip_tx_start <= '0';
135
      mac_tx_granted <= '0';
136
      mac_data_out_ready <= '0';
137
                ip_tx.data.data_out_valid <= '0';
138
                ip_tx.data.data_out_last <= '0';
139 4 pjf
                arp_req_rslt.got_mac <= '0';
140
                arp_req_rslt.got_err <= '0';
141
                arp_req_rslt.mac <=  (others => '0');
142 2 pjf
 
143
                reset <= '1';
144
      wait for clk_period*10;
145
                reset <= '0';
146
      wait for clk_period*5;
147
 
148
                -- check reset conditions
149
                assert arp_req_req.lookup_req = '0'                      report "arp_req_req.lookup_req not initialised correctly on reset";
150
                assert ip_tx_result = IPTX_RESULT_NONE  report "ip_tx_result not initialised correctly on reset";
151
                assert ip_tx_data_out_ready = '0' report "ip_tx_data_out_ready not initialised correctly on reset";
152
                assert mac_tx_req = '0'                                  report "mac_tx_req not initialised correctly on reset";
153
                assert mac_data_out_valid = '0'                  report "mac_data_out_valid not initialised correctly on reset";
154
                assert mac_data_out_last = '0'                   report "mac_data_out_last not initialised correctly on reset";
155
 
156
      -- insert stimulus here 
157
 
158
                ------------
159
                -- TEST 1 -- basic functional tx test with some delays for arp and chn access
160
                ------------
161
 
162
                report "T1: basic functional tx test with some delays for arp and chn access";
163
 
164
                ip_tx.hdr.protocol <= x"35";
165
                ip_tx.hdr.data_length <= x"0008";
166
                ip_tx.hdr.dst_ip_addr <= x"c0123478";
167
                ip_tx_start <= '1';
168
                wait for clk_period;
169
                ip_tx_start <= '0'; wait for clk_period;
170
                arp_req_rslt.got_mac <= '0';
171 4 pjf
                arp_req_rslt.got_err <= '0';
172 2 pjf
 
173
                assert arp_req_req.lookup_req = '1'                                     report "T1: lookup_req not set on tx start";
174
                assert ip_tx_result = IPTX_RESULT_SENDING               report "T1: result should be IPTX_RESULT_SENDING";
175
 
176
                wait for clk_period*10;         -- simulate arp lookup time
177
                arp_req_rslt.mac <= x"050423271016";
178
                arp_req_rslt.got_mac <= '1';
179
 
180
                wait for clk_period*2;
181
 
182
                assert arp_req_req.lookup_req = '0'                      report "T1: lookup_req not clear after setting";
183
                assert mac_tx_req = '1'                                         report "T1: mac_tx_req not set after getting mac";
184
 
185
                wait for clk_period*10;         -- simulate mac chn access time
186
                mac_tx_granted <= '1';
187
                wait for clk_period*2;
188
      mac_data_out_ready <= '1';
189
                assert mac_data_out_valid = '0'                  report "T1: mac_data_out_valid asserted too early";
190
 
191
                wait for clk_period;
192
 
193
                assert ip_tx_data_out_ready = '0'        report "T1: IP data out ready asserted too early";
194
                wait for clk_period;
195
                assert mac_data_out_valid = '1'                 report "T1: mac_data_out_valid not asserted";
196
 
197
                -- wait until in eth hdr
198
                wait for clk_period*3;
199
                -- go mac not ready for 2 clocks
200
      mac_data_out_ready <= '0';
201
                wait for clk_period*2;
202
      mac_data_out_ready <= '1';
203
 
204
 
205
                wait until ip_tx_data_out_ready = '1';
206
 
207
                -- start to tx IP data
208
                ip_tx.data.data_out_valid <= '1';
209
                ip_tx.data.data_out <= x"56"; wait for clk_period;
210
                -- delay data in for 1 clk cycle
211
                ip_tx.data.data_out_valid <= '0';
212
                ip_tx.data.data_out <= x"57"; wait for clk_period;
213
                ip_tx.data.data_out_valid <= '1'; wait for clk_period;
214
                ip_tx.data.data_out <= x"58"; wait for clk_period;
215
                ip_tx.data.data_out <= x"59"; wait for clk_period;
216
 
217
                -- delay mac ready for 2 clk cycles
218
                mac_data_out_ready <= '0';
219
                ip_tx.data.data_out <= x"5a"; wait for clk_period;
220
                assert ip_tx_data_out_ready = '0'                        report "T1: ip_tx_data_out_ready not cleared when mac not ready";
221
 
222
                ip_tx.data.data_out <= x"5a"; wait for clk_period;
223
                mac_data_out_ready <= '1';
224
                wait until ip_tx_data_out_ready = '1';
225
                wait for clk_period;
226
                assert ip_tx_data_out_ready = '1'                       report "T1: ip_tx_data_out_ready not set when mac ready";
227
                ip_tx.data.data_out <= x"5b"; wait for clk_period;
228
                ip_tx.data.data_out <= x"5c"; wait for clk_period;
229
 
230
                ip_tx.data.data_out <= x"5d";
231
                ip_tx.data.data_out_last <= '1';
232
                wait for clk_period;
233
                assert mac_data_out_last = '1'                  report "T1: mac_datda_out_last not set on last byte";
234
 
235
                ip_tx.data.data_out_valid <= '0';
236
                ip_tx.data.data_out_last <= '0';
237
                wait for clk_period*2;
238
 
239
                assert ip_tx_result = IPTX_RESULT_SENT  report "T1: result should be IPTX_RESULT_SENT";
240
                assert mac_tx_req = '0'                                  report "T1: mac_tx_req held on too long after TX";
241
 
242
                mac_tx_granted <= '0';
243
                wait for clk_period*2;
244
 
245
                ------------
246
                -- TEST 2 -- basic functional tx test with no delays for arp and chn access
247
                ------------
248
 
249
                report "T2: basic functional tx test with no delays for arp and chn access";
250
 
251
                ip_tx.hdr.protocol <= x"11";
252
                ip_tx.hdr.data_length <= x"0006";
253
                ip_tx.hdr.dst_ip_addr <= x"c0123478";
254
                ip_tx_start <= '1';
255
                wait for clk_period;
256
                ip_tx_start <= '0'; wait for clk_period;
257
                arp_req_rslt.got_mac <= '0';
258
 
259 6 pjf
                assert arp_req_req.lookup_req = '1'                     report "T2: lookup_req not set on tx start";
260
                assert ip_tx_result = IPTX_RESULT_SENDING               report "T2: result should be IPTX_RESULT_SENDING";
261 2 pjf
 
262
                wait for clk_period;            -- simulate arp lookup time
263
                arp_req_rslt.mac <= x"050423271016";
264
                arp_req_rslt.got_mac <= '1';
265
 
266
                wait for clk_period*2;
267
 
268 6 pjf
                assert arp_req_req.lookup_req = '0'                      report "T2: lookup_req not clear after setting";
269
                assert mac_tx_req = '1'                                                         report "T2: mac_tx_req not set after getting mac";
270 2 pjf
 
271
                wait for clk_period;            -- simulate mac chn access time
272
                mac_tx_granted <= '1';
273
                wait for clk_period*2;
274
      mac_data_out_ready <= '1';
275
 
276 6 pjf
                assert ip_tx_data_out_ready = '0'                                report "T2: IP data out ready asserted too early";
277 2 pjf
 
278
                wait until ip_tx_data_out_ready = '1';
279
 
280
                -- start to tx IP data
281
                ip_tx.data.data_out_valid <= '1';
282
                ip_tx.data.data_out <= x"c1"; wait for clk_period;
283
                ip_tx.data.data_out <= x"c2"; wait for clk_period;
284
                ip_tx.data.data_out <= x"c3"; wait for clk_period;
285
                ip_tx.data.data_out <= x"c4"; wait for clk_period;
286
                ip_tx.data.data_out <= x"c5"; wait for clk_period;
287
 
288
                ip_tx.data.data_out <= x"c6";
289
                ip_tx.data.data_out_last <= '1';
290
                wait for clk_period;
291
 
292 6 pjf
                assert mac_data_out_last = '1'                                  report "T2: mac_datda_out_last not set on last byte";
293 2 pjf
 
294
 
295
                ip_tx.data.data_out_valid <= '0';
296
                ip_tx.data.data_out_last <= '0';
297
                wait for clk_period*2;
298
 
299 6 pjf
                assert ip_tx_result = IPTX_RESULT_SENT                  report "T2: result should be IPTX_RESULT_SENT";
300
                assert mac_tx_req = '0'                                                  report "T2: mac_tx_req held on too long after TX";
301 2 pjf
 
302
                mac_tx_granted <= '0';
303
                wait for clk_period*2;
304
 
305 6 pjf
                ------------
306
                -- TEST 3 -- tx test for IP broadcast, should be no arp req
307
                ------------
308
 
309
                report "T3: tx test for IP broadcast, should be no arp req";
310
 
311
                ip_tx.hdr.protocol <= x"11";
312
                ip_tx.hdr.data_length <= x"0006";
313
                ip_tx.hdr.dst_ip_addr <= x"ffffffff";
314
                ip_tx_start <= '1';
315
                wait for clk_period;
316
                ip_tx_start <= '0'; wait for clk_period;
317
                arp_req_rslt.got_mac <= '0';
318
 
319
                assert arp_req_req.lookup_req = '0'                      report "T3: its trying to do an ARP req tx start";
320
                assert ip_tx_result = IPTX_RESULT_SENDING               report "T3: result should be IPTX_RESULT_SENDING";
321
 
322
                wait for clk_period;            -- simulate mac chn access time
323
                mac_tx_granted <= '1';
324
                wait for clk_period*2;
325
      mac_data_out_ready <= '1';
326
 
327
                assert ip_tx_data_out_ready = '0'                                report "T3: IP data out ready asserted too early";
328
 
329
                wait until ip_tx_data_out_ready = '1';
330
 
331
                -- start to tx IP data
332
                ip_tx.data.data_out_valid <= '1';
333
                ip_tx.data.data_out <= x"c1"; wait for clk_period;
334
                ip_tx.data.data_out <= x"c2"; wait for clk_period;
335
                ip_tx.data.data_out <= x"c3"; wait for clk_period;
336
                ip_tx.data.data_out <= x"c4"; wait for clk_period;
337
                ip_tx.data.data_out <= x"c5"; wait for clk_period;
338
 
339
                ip_tx.data.data_out <= x"c6";
340
                ip_tx.data.data_out_last <= '1';
341
                wait for clk_period;
342
 
343
                assert mac_data_out_last = '1'                                  report "T3: mac_datda_out_last not set on last byte";
344
 
345
 
346
                ip_tx.data.data_out_valid <= '0';
347
                ip_tx.data.data_out_last <= '0';
348
                wait for clk_period*2;
349
 
350
                assert ip_tx_result = IPTX_RESULT_SENT                  report "T3: result should be IPTX_RESULT_SENT";
351
                assert mac_tx_req = '0'                                                  report "T3: mac_tx_req held on too long after TX";
352
 
353
                mac_tx_granted <= '0';
354
                wait for clk_period*2;
355
 
356
 
357 2 pjf
                report "--- end of tests ---";
358
 
359
      wait;
360
   end process;
361
 
362
END;

powered by: WebSVN 2.1.0

© copyright 1999-2022 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.