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

powered by: WebSVN 2.1.0

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