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 8

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 8 pjf
                ip_tx_start <= '0';
170 2 pjf
                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 8 pjf
                wait for clk_period;
175 2 pjf
                assert ip_tx_result = IPTX_RESULT_SENDING               report "T1: result should be IPTX_RESULT_SENDING";
176
 
177
                wait for clk_period*10;         -- simulate arp lookup time
178
                arp_req_rslt.mac <= x"050423271016";
179
                arp_req_rslt.got_mac <= '1';
180
 
181
                wait for clk_period*2;
182
 
183
                assert arp_req_req.lookup_req = '0'                      report "T1: lookup_req not clear after setting";
184
                assert mac_tx_req = '1'                                         report "T1: mac_tx_req not set after getting mac";
185
 
186
                wait for clk_period*10;         -- simulate mac chn access time
187
                mac_tx_granted <= '1';
188
                wait for clk_period*2;
189
      mac_data_out_ready <= '1';
190
                assert mac_data_out_valid = '0'                  report "T1: mac_data_out_valid asserted too early";
191
 
192
                wait for clk_period;
193
 
194
                assert ip_tx_data_out_ready = '0'        report "T1: IP data out ready asserted too early";
195
                wait for clk_period;
196
                assert mac_data_out_valid = '1'                 report "T1: mac_data_out_valid not asserted";
197
 
198
                -- wait until in eth hdr
199
                wait for clk_period*3;
200
                -- go mac not ready for 2 clocks
201
      mac_data_out_ready <= '0';
202
                wait for clk_period*2;
203
      mac_data_out_ready <= '1';
204
 
205
 
206
                wait until ip_tx_data_out_ready = '1';
207
 
208
                -- start to tx IP data
209
                ip_tx.data.data_out_valid <= '1';
210
                ip_tx.data.data_out <= x"56"; wait for clk_period;
211
                -- delay data in for 1 clk cycle
212
                ip_tx.data.data_out_valid <= '0';
213
                ip_tx.data.data_out <= x"57"; wait for clk_period;
214
                ip_tx.data.data_out_valid <= '1'; wait for clk_period;
215
                ip_tx.data.data_out <= x"58"; wait for clk_period;
216
                ip_tx.data.data_out <= x"59"; wait for clk_period;
217
 
218
                -- delay mac ready for 2 clk cycles
219
                mac_data_out_ready <= '0';
220
                ip_tx.data.data_out <= x"5a"; wait for clk_period;
221
                assert ip_tx_data_out_ready = '0'                        report "T1: ip_tx_data_out_ready not cleared when mac not ready";
222
 
223
                ip_tx.data.data_out <= x"5a"; wait for clk_period;
224
                mac_data_out_ready <= '1';
225
                wait until ip_tx_data_out_ready = '1';
226
                wait for clk_period;
227
                assert ip_tx_data_out_ready = '1'                       report "T1: ip_tx_data_out_ready not set when mac ready";
228
                ip_tx.data.data_out <= x"5b"; wait for clk_period;
229
                ip_tx.data.data_out <= x"5c"; wait for clk_period;
230
 
231
                ip_tx.data.data_out <= x"5d";
232
                ip_tx.data.data_out_last <= '1';
233
                wait for clk_period;
234
                assert mac_data_out_last = '1'                  report "T1: mac_datda_out_last not set on last byte";
235
 
236
                ip_tx.data.data_out_valid <= '0';
237
                ip_tx.data.data_out_last <= '0';
238
                wait for clk_period*2;
239
 
240
                assert ip_tx_result = IPTX_RESULT_SENT  report "T1: result should be IPTX_RESULT_SENT";
241
                assert mac_tx_req = '0'                                  report "T1: mac_tx_req held on too long after TX";
242
 
243
                mac_tx_granted <= '0';
244
                wait for clk_period*2;
245
 
246
                ------------
247
                -- TEST 2 -- basic functional tx test with no delays for arp and chn access
248
                ------------
249
 
250
                report "T2: basic functional tx test with no delays for arp and chn access";
251
 
252
                ip_tx.hdr.protocol <= x"11";
253
                ip_tx.hdr.data_length <= x"0006";
254
                ip_tx.hdr.dst_ip_addr <= x"c0123478";
255
                ip_tx_start <= '1';
256
                wait for clk_period;
257
                ip_tx_start <= '0'; wait for clk_period;
258
                arp_req_rslt.got_mac <= '0';
259
 
260 6 pjf
                assert arp_req_req.lookup_req = '1'                     report "T2: lookup_req not set on tx start";
261
                assert ip_tx_result = IPTX_RESULT_SENDING               report "T2: result should be IPTX_RESULT_SENDING";
262 2 pjf
 
263
                wait for clk_period;            -- simulate arp lookup time
264
                arp_req_rslt.mac <= x"050423271016";
265
                arp_req_rslt.got_mac <= '1';
266
 
267
                wait for clk_period*2;
268
 
269 6 pjf
                assert arp_req_req.lookup_req = '0'                      report "T2: lookup_req not clear after setting";
270
                assert mac_tx_req = '1'                                                         report "T2: mac_tx_req not set after getting mac";
271 2 pjf
 
272
                wait for clk_period;            -- simulate mac chn access time
273
                mac_tx_granted <= '1';
274
                wait for clk_period*2;
275
      mac_data_out_ready <= '1';
276
 
277 6 pjf
                assert ip_tx_data_out_ready = '0'                                report "T2: IP data out ready asserted too early";
278 2 pjf
 
279
                wait until ip_tx_data_out_ready = '1';
280
 
281
                -- start to tx IP data
282
                ip_tx.data.data_out_valid <= '1';
283
                ip_tx.data.data_out <= x"c1"; wait for clk_period;
284
                ip_tx.data.data_out <= x"c2"; wait for clk_period;
285
                ip_tx.data.data_out <= x"c3"; wait for clk_period;
286
                ip_tx.data.data_out <= x"c4"; wait for clk_period;
287
                ip_tx.data.data_out <= x"c5"; wait for clk_period;
288
 
289
                ip_tx.data.data_out <= x"c6";
290
                ip_tx.data.data_out_last <= '1';
291
                wait for clk_period;
292
 
293 6 pjf
                assert mac_data_out_last = '1'                                  report "T2: mac_datda_out_last not set on last byte";
294 2 pjf
 
295
 
296
                ip_tx.data.data_out_valid <= '0';
297
                ip_tx.data.data_out_last <= '0';
298
                wait for clk_period*2;
299
 
300 6 pjf
                assert ip_tx_result = IPTX_RESULT_SENT                  report "T2: result should be IPTX_RESULT_SENT";
301
                assert mac_tx_req = '0'                                                  report "T2: mac_tx_req held on too long after TX";
302 2 pjf
 
303
                mac_tx_granted <= '0';
304
                wait for clk_period*2;
305
 
306 6 pjf
                ------------
307
                -- TEST 3 -- tx test for IP broadcast, should be no arp req
308
                ------------
309
 
310
                report "T3: tx test for IP broadcast, should be no arp req";
311
 
312
                ip_tx.hdr.protocol <= x"11";
313
                ip_tx.hdr.data_length <= x"0006";
314
                ip_tx.hdr.dst_ip_addr <= x"ffffffff";
315
                ip_tx_start <= '1';
316
                wait for clk_period;
317
                ip_tx_start <= '0'; wait for clk_period;
318
                arp_req_rslt.got_mac <= '0';
319
 
320
                assert arp_req_req.lookup_req = '0'                      report "T3: its trying to do an ARP req tx start";
321
                assert ip_tx_result = IPTX_RESULT_SENDING               report "T3: result should be IPTX_RESULT_SENDING";
322
 
323
                wait for clk_period;            -- simulate mac chn access time
324
                mac_tx_granted <= '1';
325
                wait for clk_period*2;
326
      mac_data_out_ready <= '1';
327
 
328
                assert ip_tx_data_out_ready = '0'                                report "T3: IP data out ready asserted too early";
329
 
330
                wait until ip_tx_data_out_ready = '1';
331
 
332
                -- start to tx IP data
333
                ip_tx.data.data_out_valid <= '1';
334
                ip_tx.data.data_out <= x"c1"; wait for clk_period;
335
                ip_tx.data.data_out <= x"c2"; wait for clk_period;
336
                ip_tx.data.data_out <= x"c3"; wait for clk_period;
337
                ip_tx.data.data_out <= x"c4"; wait for clk_period;
338
                ip_tx.data.data_out <= x"c5"; wait for clk_period;
339
 
340
                ip_tx.data.data_out <= x"c6";
341
                ip_tx.data.data_out_last <= '1';
342
                wait for clk_period;
343
 
344
                assert mac_data_out_last = '1'                                  report "T3: mac_datda_out_last not set on last byte";
345
 
346
 
347
                ip_tx.data.data_out_valid <= '0';
348
                ip_tx.data.data_out_last <= '0';
349
                wait for clk_period*2;
350
 
351
                assert ip_tx_result = IPTX_RESULT_SENT                  report "T3: result should be IPTX_RESULT_SENT";
352
                assert mac_tx_req = '0'                                                  report "T3: mac_tx_req held on too long after TX";
353
 
354
                mac_tx_granted <= '0';
355
                wait for clk_period*2;
356
 
357
 
358 2 pjf
                report "--- end of tests ---";
359
 
360
      wait;
361
   end process;
362
 
363
END;

powered by: WebSVN 2.1.0

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