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

Subversion Repositories udp_ip_stack

[/] [udp_ip_stack/] [trunk/] [contrib/] [from_tim/] [udp_ip_stack/] [tags/] [v1.1/] [bench/] [vhdl/] [IPv4_TX_tb.vhd] - Blame information for rev 35

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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