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/] [IP_complete_nomac_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:   13:54:32 06/04/2011
6
-- Design Name:   
7
-- Module Name:   C:/Users/pjf/Documents/projects/fpga/xilinx/Network/ip1/IP_complete_nomac_tb.vhd
8
-- Project Name:  ip1
9
-- Target Device:  
10
-- Tool versions:  
11
-- Description:   
12
-- 
13
-- VHDL Test Bench Created by ISE for module: IP_complete_nomac
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
ENTITY IP_complete_nomac_tb IS
36
END IP_complete_nomac_tb;
37
 
38
ARCHITECTURE behavior OF IP_complete_nomac_tb IS
39
 
40
    -- Component Declaration for the Unit Under Test (UUT)
41
 
42
    COMPONENT IP_complete_nomac
43
    PORT(
44
                        -- IP Layer signals
45
                        ip_tx_start                             : in std_logic;
46
                        ip_tx                                           : in ipv4_tx_type;                                                              -- IP tx cxns
47
                        ip_tx_result                    : out std_logic_vector (1 downto 0);             -- tx status (changes during transmission)
48
                        ip_tx_data_out_ready    : out std_logic;                                                                        -- indicates IP TX is ready to take data
49
                        ip_rx_start                             : out std_logic;                                                                        -- indicates receipt of ip frame.
50
                        ip_rx                                           : out ipv4_rx_type;
51
                        -- system signals
52
                        rx_clk                                  : in  STD_LOGIC;
53
                        tx_clk                                  : in  STD_LOGIC;
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
                        -- status signals
58
                        arp_pkt_count                   : out STD_LOGIC_VECTOR(7 downto 0);                      -- count of arp pkts received
59
                        ip_pkt_count                    : out STD_LOGIC_VECTOR(7 downto 0);                      -- number of IP pkts received for us
60
                        -- MAC Transmitter
61
                        mac_tx_tdata         : out  std_logic_vector(7 downto 0);        -- data byte to tx
62
                        mac_tx_tvalid        : out  std_logic;                                                  -- tdata is valid
63
                        mac_tx_tready        : in std_logic;                                                    -- mac is ready to accept data
64
                        mac_tx_tfirst        : out  std_logic;                                                  -- indicates first byte of frame
65
                        mac_tx_tlast         : out  std_logic;                                                  -- indicates last byte of frame
66
                        -- MAC Receiver
67
                        mac_rx_tdata         : in std_logic_vector(7 downto 0);  -- data byte received
68
                        mac_rx_tvalid        : in std_logic;                                                    -- indicates tdata is valid
69
                        mac_rx_tready        : out  std_logic;                                                  -- tells mac that we are ready to take data
70
                        mac_rx_tlast         : in std_logic                                                             -- indicates last byte of the trame
71
        );
72
    END COMPONENT;
73
 
74
 
75
   --Inputs
76
   signal ip_tx_start : std_logic := '0';
77
   signal ip_tx : ipv4_tx_type;
78
 
79
   signal clk : std_logic := '0';
80
   signal reset : std_logic := '0';
81
   signal our_ip_address : std_logic_vector(31 downto 0) := (others => '0');
82
   signal our_mac_address : std_logic_vector(47 downto 0) := (others => '0');
83
   signal mac_tx_tready : std_logic := '0';
84
   signal mac_rx_tdata : std_logic_vector(7 downto 0) := (others => '0');
85
   signal mac_rx_tvalid : std_logic := '0';
86
   signal mac_rx_tlast : std_logic := '0';
87
        --Outputs
88
        signal ip_tx_result : std_logic_vector (1 downto 0);                                             -- tx status (changes during transmission)
89
        signal ip_tx_data_out_ready     :  std_logic;                                                                   -- indicates IP TX is ready to take data
90
   signal ip_rx_start : std_logic;
91
   signal ip_rx : ipv4_rx_type;
92
   signal arp_pkt_count : std_logic_vector(7 downto 0);
93
   signal mac_tx_tdata : std_logic_vector(7 downto 0);
94
   signal mac_tx_tvalid : std_logic;
95
   signal mac_tx_tfirst : std_logic;
96
   signal mac_tx_tlast : std_logic;
97
   signal mac_rx_tready : std_logic;
98
 
99
   -- Clock period definitions
100
   constant clk_period : time := 8 ns;
101
 
102
BEGIN
103
 
104
        -- Instantiate the Unit Under Test (UUT)
105
   uut: IP_complete_nomac PORT MAP (
106
          ip_tx_start => ip_tx_start,
107
          ip_tx => ip_tx,
108
          ip_tx_result => ip_tx_result,
109
          ip_tx_data_out_ready => ip_tx_data_out_ready,
110
          ip_rx_start => ip_rx_start,
111
          ip_rx => ip_rx,
112
          rx_clk => clk,
113
          tx_clk => clk,
114
          reset => reset,
115
          our_ip_address => our_ip_address,
116
          our_mac_address => our_mac_address,
117
          arp_pkt_count => arp_pkt_count,
118
          mac_tx_tdata => mac_tx_tdata,
119
          mac_tx_tvalid => mac_tx_tvalid,
120
          mac_tx_tready => mac_tx_tready,
121
                         mac_tx_tfirst => mac_tx_tfirst,
122
          mac_tx_tlast => mac_tx_tlast,
123
          mac_rx_tdata => mac_rx_tdata,
124
          mac_rx_tvalid => mac_rx_tvalid,
125
          mac_rx_tready => mac_rx_tready,
126
          mac_rx_tlast => mac_rx_tlast
127
        );
128
 
129
   -- Clock process definitions
130
   clk_process :process
131
   begin
132
                clk <= '1';
133
                wait for clk_period/2;
134
                clk <= '0';
135
                wait for clk_period/2;
136
   end process;
137
 
138
 
139
   -- Stimulus process
140
   stim_proc: process
141
   begin
142
      -- hold reset state for 100 ns.
143
      wait for 80 ns;
144
 
145
                our_ip_address <= x"c0a80509";          -- 192.168.5.9
146
                our_mac_address <= x"002320212223";
147
                ip_tx_start <= '0';
148
      mac_tx_tready <= '0';
149
 
150
                reset <= '1';
151
      wait for clk_period*10;
152
                reset <= '0';
153
      wait for clk_period*5;
154
 
155
                -- check reset conditions
156
                assert ip_tx_result = IPTX_RESULT_NONE                  report "ip_tx_result not initialised correctly on reset";
157
                assert ip_tx_data_out_ready = '0'                report "ip_tx_data_out_ready not initialised correctly on reset";
158
                assert mac_tx_tvalid = '0'                                               report "mac_tx_tvalid not initialised correctly on reset";
159
                assert mac_tx_tlast = '0'                                                        report " mac_tx_tlast not initialised correctly on reset";
160
                assert arp_pkt_count = x"00"                                            report " arp_pkt_count not initialised correctly on reset";
161
                assert ip_rx_start = '0'                                                         report "ip_rx_start not initialised correctly on reset";
162
                assert ip_rx.hdr.is_valid = '0'                                  report "ip_rx.hdr.is_valid not initialised correctly on reset";
163
                assert ip_rx.hdr.protocol = x"00"                               report "ip_rx.hdr.protocol not initialised correctly on reset";
164
                assert ip_rx.hdr.data_length = x"0000"                  report "ip_rx.hdr.data_length not initialised correctly on reset";
165
                assert ip_rx.hdr.src_ip_addr = x"00000000"      report "ip_rx.hdr.src_ip_addr not initialised correctly on reset";
166
                assert ip_rx.hdr.num_frame_errors = x"00"               report "ip_rx.hdr.num_frame_errors not initialised correctly on reset";
167
                assert ip_rx.data.data_in = x"00"                               report "ip_rx.data.data_in not initialised correctly on reset";
168
                assert ip_rx.data.data_in_valid = '0'                    report "ip_rx.data.data_in_valid not initialised correctly on reset";
169
                assert ip_rx.data.data_in_last = '0'                     report "ip_rx.data.data_in_last not initialised correctly on reset";
170
 
171
      -- insert stimulus here 
172
 
173
                ------------
174
                -- TEST 1 -- basic functional rx test with received ip pkt
175
                ------------
176
 
177
                report "T1: Send an eth frame with IP pkt dst ip_address c0a80509, dst mac 002320212223";
178
 
179
      mac_tx_tready <= '1';
180
                mac_rx_tvalid <= '1';
181
                -- dst MAC (bc)
182
                mac_rx_tdata <= x"00"; wait for clk_period;
183
                mac_rx_tdata <= x"23"; wait for clk_period;
184
                mac_rx_tdata <= x"20"; wait for clk_period;
185
                mac_rx_tdata <= x"21"; wait for clk_period;
186
                mac_rx_tdata <= x"22"; wait for clk_period;
187
                mac_rx_tdata <= x"23"; wait for clk_period;
188
                -- src MAC
189
                mac_rx_tdata <= x"00"; wait for clk_period;
190
                mac_rx_tdata <= x"23"; wait for clk_period;
191
                mac_rx_tdata <= x"18"; wait for clk_period;
192
                mac_rx_tdata <= x"29"; wait for clk_period;
193
                mac_rx_tdata <= x"26"; wait for clk_period;
194
                mac_rx_tdata <= x"7c"; wait for clk_period;
195
                -- type
196
                mac_rx_tdata <= x"08"; wait for clk_period;             -- IP pkt
197
                mac_rx_tdata <= x"00"; wait for clk_period;
198
                -- ver & HL / service type
199
                mac_rx_tdata <= x"45"; wait for clk_period;
200
                mac_rx_tdata <= x"00"; wait for clk_period;
201
                -- total len
202
                mac_rx_tdata <= x"00"; wait for clk_period;
203
                mac_rx_tdata <= x"18"; wait for clk_period;
204
                -- ID
205
                mac_rx_tdata <= x"00"; wait for clk_period;
206
                mac_rx_tdata <= x"00"; wait for clk_period;
207
                -- flags & frag
208
                mac_rx_tdata <= x"00"; wait for clk_period;
209
                mac_rx_tdata <= x"00"; wait for clk_period;
210
                -- TTL
211
                mac_rx_tdata <= x"00"; wait for clk_period;
212
                -- Protocol
213
                mac_rx_tdata <= x"11"; wait for clk_period;
214
                -- Header CKS
215
                mac_rx_tdata <= x"00"; wait for clk_period;
216
                mac_rx_tdata <= x"00"; wait for clk_period;
217
                -- SRC IP
218
                mac_rx_tdata <= x"c0"; wait for clk_period;
219
                mac_rx_tdata <= x"a8"; wait for clk_period;
220
                mac_rx_tdata <= x"05"; wait for clk_period;
221
                mac_rx_tdata <= x"01"; wait for clk_period;
222
                -- DST IP
223
                mac_rx_tdata <= x"c0"; wait for clk_period;
224
                mac_rx_tdata <= x"a8"; wait for clk_period;
225
                mac_rx_tdata <= x"05"; wait for clk_period;
226
                mac_rx_tdata <= x"09"; wait for clk_period;
227
 
228
                -- user data
229
                mac_rx_tdata <= x"24"; wait for clk_period;
230
 
231
                -- since we are up to the user data stage, the header should be valid and the data_in_valid should be set
232
                assert ip_rx.hdr.is_valid = '1'                                 report "T1: ip_rx.hdr.is_valid not set";
233
                assert ip_rx.hdr.protocol = x"11"                               report "T1: ip_rx.hdr.protocol not set correctly";
234
                assert ip_rx.hdr.data_length = x"0004"                  report "T1: ip_rx.hdr.data_length not set correctly";
235
                assert ip_rx.hdr.src_ip_addr = x"c0a80501"      report "T1: ip_rx.hdr.src_ip_addr not set correctly";
236
                assert ip_rx.hdr.num_frame_errors = x"00"               report "T1: ip_rx.hdr.num_frame_errors not set correctly";
237
                assert ip_rx.hdr.last_error_code = x"0"          report "T1: ip_rx.hdr.last_error_code not set correctly";
238
                assert ip_rx_start = '1'                                                        report "T1: ip_rx_start not set";
239
                assert ip_rx.data.data_in_valid = '1'                   report "T1: ip_rx.data.data_in_valid not set";
240
 
241
                mac_rx_tdata <= x"25"; wait for clk_period;
242
                mac_rx_tdata <= x"26"; wait for clk_period;
243
                mac_rx_tdata <= x"27"; mac_rx_tlast <= '1'; wait for clk_period;
244
 
245
                assert ip_rx.data.data_in_last = '1'                    report "T1: ip_rx.data.data_in_last not set";
246
 
247
 
248
                mac_rx_tdata <= x"00";
249
                mac_rx_tlast <= '0';
250
                mac_rx_tvalid <= '0';
251
                wait for clk_period;
252
 
253
                assert ip_rx.data.data_in_valid = '0'                    report "T1: ip_rx.data.data_in_valid not cleared";
254
                assert ip_rx.data.data_in_last = '0'                     report "T1: ip_rx.data.data_in_last not cleared";
255
                assert ip_rx.hdr.num_frame_errors = x"00"               report "T1: ip_rx.hdr.num_frame_errors non zero at end of test";
256
                assert ip_rx.hdr.last_error_code = x"0"          report "T1: ip_rx.hdr.last_error_code indicates error at end of test";
257
                assert ip_rx_start = '0'                                                 report "T1: ip_rx_start not cleared";
258
 
259
                ------------
260
                -- TEST 2 -- respond with IP TX
261
                ------------
262
 
263
                report "T2: respond with IP TX";
264
 
265
                ip_tx.hdr.protocol <= x"35";
266
                ip_tx.hdr.data_length <= x"0006";
267
                ip_tx.hdr.dst_ip_addr <= x"c0123478";
268
                ip_tx.data.data_out_valid <= '0';
269
                ip_tx.data.data_out_last <= '0';
270
                wait for clk_period;
271
 
272
                ip_tx_start <= '1'; wait for clk_period;
273
 
274
                ip_tx_start <= '0'; wait for clk_period;
275
 
276
                assert ip_tx_result = IPTX_RESULT_SENDING               report "T1: result should be IPTX_RESULT_SENDING";
277
 
278
                wait for clk_period*2;
279
 
280
                assert ip_tx_data_out_ready = '0'                        report "T2: IP data out ready asserted too early";
281
 
282
                -- need to wait for ARP tx to complete
283
 
284
                wait for clk_period*50;
285
 
286
                assert mac_tx_tvalid = '0'                                               report "T2: mac_tx_tvalid not cleared after ARP tx";
287
                assert mac_tx_tlast = '0'                                                        report "T2: mac_tx_tlast not cleared after ARP tx";
288
 
289
                -- now create the ARP response (rx)
290
 
291
                -- Send the reply
292
                -- Send an ARP reply: x"c0123478" has mac 02:12:03:23:04:54
293
                mac_rx_tvalid <= '1';
294
                -- dst MAC (bc)
295
                mac_rx_tdata <= x"ff"; wait for clk_period;
296
                mac_rx_tdata <= x"ff"; wait for clk_period;
297
                mac_rx_tdata <= x"ff"; wait for clk_period;
298
                mac_rx_tdata <= x"ff"; wait for clk_period;
299
                mac_rx_tdata <= x"ff"; wait for clk_period;
300
                mac_rx_tdata <= x"ff"; wait for clk_period;
301
                -- src MAC
302
                mac_rx_tdata <= x"02"; wait for clk_period;
303
                mac_rx_tdata <= x"12"; wait for clk_period;
304
                mac_rx_tdata <= x"03"; wait for clk_period;
305
                mac_rx_tdata <= x"23"; wait for clk_period;
306
                mac_rx_tdata <= x"04"; wait for clk_period;
307
                mac_rx_tdata <= x"54"; wait for clk_period;
308
                -- type
309
                mac_rx_tdata <= x"08"; wait for clk_period;
310
                mac_rx_tdata <= x"06"; wait for clk_period;
311
                -- HW type
312
                mac_rx_tdata <= x"00"; wait for clk_period;
313
                mac_rx_tdata <= x"01"; wait for clk_period;
314
                -- Protocol type
315
                mac_rx_tdata <= x"08"; wait for clk_period;
316
                mac_rx_tdata <= x"00"; wait for clk_period;
317
                -- HW size
318
                mac_rx_tdata <= x"06"; wait for clk_period;
319
                -- protocol size
320
                mac_rx_tdata <= x"04"; wait for clk_period;
321
                -- Opcode
322
                mac_rx_tdata <= x"00"; wait for clk_period;
323
                mac_rx_tdata <= x"02"; wait for clk_period;
324
                -- Sender MAC
325
                mac_rx_tdata <= x"02"; wait for clk_period;
326
                mac_rx_tdata <= x"12"; wait for clk_period;
327
                mac_rx_tdata <= x"03"; wait for clk_period;
328
                mac_rx_tdata <= x"23"; wait for clk_period;
329
                mac_rx_tdata <= x"04"; wait for clk_period;
330
                mac_rx_tdata <= x"54"; wait for clk_period;
331
                -- Sender IP
332
                mac_rx_tdata <= x"c0"; wait for clk_period;
333
                mac_rx_tdata <= x"12"; wait for clk_period;
334
                mac_rx_tdata <= x"34"; wait for clk_period;
335
                mac_rx_tdata <= x"78"; wait for clk_period;
336
                -- Target MAC
337
                mac_rx_tdata <= x"00"; wait for clk_period;
338
                mac_rx_tdata <= x"23"; wait for clk_period;
339
                mac_rx_tdata <= x"20"; wait for clk_period;
340
                mac_rx_tdata <= x"21"; wait for clk_period;
341
                mac_rx_tdata <= x"22"; wait for clk_period;
342
                mac_rx_tdata <= x"23"; wait for clk_period;
343
                -- Target IP
344
                mac_rx_tdata <= x"c0"; wait for clk_period;
345
                mac_rx_tdata <= x"a8"; wait for clk_period;
346
                mac_rx_tdata <= x"05"; wait for clk_period;
347
                mac_rx_tdata <= x"09"; wait for clk_period;
348
                mac_rx_tdata <= x"00"; wait for clk_period;
349
                mac_rx_tdata <= x"00"; wait for clk_period;
350
                mac_rx_tdata <= x"00"; wait for clk_period;
351
                mac_rx_tlast <= '1';
352
                mac_rx_tdata <= x"00"; wait for clk_period;
353
                mac_rx_tlast <= '0';
354
                mac_rx_tvalid <= '0';
355
 
356
                wait until ip_tx_data_out_ready = '1';
357
 
358
                -- start to tx IP data
359
                ip_tx.data.data_out_valid <= '1';
360
                ip_tx.data.data_out <= x"56"; wait for clk_period;
361
                ip_tx.data.data_out <= x"57"; wait for clk_period;
362
                ip_tx.data.data_out <= x"58"; wait for clk_period;
363
                ip_tx.data.data_out <= x"59"; wait for clk_period;
364
                ip_tx.data.data_out <= x"5a"; wait for clk_period;
365
 
366
                ip_tx.data.data_out <= x"5b";
367
                ip_tx.data.data_out_last <= '1';
368
                wait for clk_period;
369
 
370
                assert mac_tx_tlast = '1'                       report "T1: mac_tx_tlast not set on last byte";
371
 
372
                wait for clk_period;
373
 
374
                ip_tx.data.data_out_valid <= '0';
375
                ip_tx.data.data_out_last <= '0';
376
                wait for clk_period*2;
377
 
378
                assert ip_tx_result = IPTX_RESULT_SENT  report "T1: result should be SENT";
379
                wait for clk_period*2;
380
 
381
 
382
                report "-- end of tests --";
383
 
384
      wait;
385
   end process;
386
 
387
END;

powered by: WebSVN 2.1.0

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