1 |
2 |
pjf |
--------------------------------------------------------------------------------
|
2 |
|
|
-- Company:
|
3 |
|
|
-- Engineer:
|
4 |
|
|
--
|
5 |
|
|
-- Create Date: 12:35:50 05/31/2011
|
6 |
|
|
-- Design Name:
|
7 |
|
|
-- Module Name: C:/Users/pjf/Documents/projects/fpga/xilinx/Network/arp1/arp_tb.vhd
|
8 |
|
|
-- Project Name: arp1
|
9 |
|
|
-- Target Device:
|
10 |
|
|
-- Tool versions:
|
11 |
|
|
-- Description:
|
12 |
|
|
--
|
13 |
|
|
-- VHDL Test Bench Created by ISE for module: arp
|
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.arp_types.all;
|
32 |
|
|
|
33 |
|
|
ENTITY arp_tb IS
|
34 |
|
|
END arp_tb;
|
35 |
|
|
|
36 |
|
|
ARCHITECTURE behavior OF arp_tb IS
|
37 |
|
|
|
38 |
|
|
-- Component Declaration for the Unit Under Test (UUT)
|
39 |
|
|
|
40 |
|
|
COMPONENT arp
|
41 |
|
|
PORT(
|
42 |
|
|
-- lookup request signals
|
43 |
|
|
arp_req_req : in arp_req_req_type;
|
44 |
|
|
arp_req_rslt : out arp_req_rslt_type;
|
45 |
|
|
-- MAC layer RX signals
|
46 |
|
|
data_in_clk : in STD_LOGIC;
|
47 |
|
|
reset : in STD_LOGIC;
|
48 |
|
|
data_in : in STD_LOGIC_VECTOR (7 downto 0); -- ethernet frame (from dst mac addr through to last byte of frame)
|
49 |
|
|
data_in_valid : in STD_LOGIC; -- indicates data_in valid on clock
|
50 |
|
|
data_in_last : in STD_LOGIC; -- indicates last data in frame
|
51 |
|
|
-- MAC layer TX signals
|
52 |
|
|
mac_tx_req : out std_logic; -- indicates that ip wants access to channel (stays up for as long as tx)
|
53 |
|
|
mac_tx_granted : in std_logic; -- indicates that access to channel has been granted
|
54 |
|
|
data_out_clk : in std_logic;
|
55 |
|
|
data_out_ready : in std_logic; -- indicates system ready to consume data
|
56 |
|
|
data_out_valid : out std_logic; -- indicates data out is valid
|
57 |
4 |
pjf |
data_out_first : out std_logic; -- with data out valid indicates the first byte of a frame
|
58 |
2 |
pjf |
data_out_last : out std_logic; -- with data out valid indicates the last byte of a frame
|
59 |
|
|
data_out : out std_logic_vector (7 downto 0); -- ethernet frame (from dst mac addr through to last byte of frame)
|
60 |
|
|
-- system signals
|
61 |
|
|
our_mac_address : in STD_LOGIC_VECTOR (47 downto 0);
|
62 |
|
|
our_ip_address : in STD_LOGIC_VECTOR (31 downto 0);
|
63 |
|
|
req_count : out STD_LOGIC_VECTOR(7 downto 0) -- count of arp pkts received
|
64 |
|
|
);
|
65 |
|
|
END COMPONENT;
|
66 |
|
|
|
67 |
|
|
|
68 |
|
|
--Inputs
|
69 |
|
|
signal clk : std_logic := '0';
|
70 |
|
|
signal reset : std_logic := '0';
|
71 |
|
|
signal data_in : std_logic_vector(7 downto 0) := (others => '0');
|
72 |
|
|
signal data_in_valid : std_logic := '0';
|
73 |
|
|
signal data_in_last : std_logic := '0';
|
74 |
|
|
signal our_mac_address : std_logic_vector(47 downto 0) := (others => '0');
|
75 |
|
|
signal our_ip_address : std_logic_vector(31 downto 0) := (others => '0');
|
76 |
|
|
signal data_out_ready : std_logic;
|
77 |
|
|
signal data_out_valid : std_logic;
|
78 |
4 |
pjf |
signal data_out_first : std_logic;
|
79 |
2 |
pjf |
signal data_out_last : std_logic;
|
80 |
|
|
signal data_out : std_logic_vector (7 downto 0);
|
81 |
|
|
signal req_count : STD_LOGIC_VECTOR(7 downto 0);
|
82 |
|
|
signal arp_req_req : arp_req_req_type;
|
83 |
|
|
signal arp_req_rslt : arp_req_rslt_type;
|
84 |
|
|
signal mac_tx_req : std_logic;
|
85 |
|
|
signal mac_tx_granted : std_logic;
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
-- Clock period definitions
|
89 |
|
|
constant clk_period : time := 8 ns;
|
90 |
|
|
|
91 |
|
|
BEGIN
|
92 |
|
|
|
93 |
|
|
-- Instantiate the Unit Under Test (UUT)
|
94 |
|
|
uut: arp PORT MAP (
|
95 |
|
|
-- lookup request mappings
|
96 |
|
|
arp_req_req => arp_req_req,
|
97 |
|
|
arp_req_rslt => arp_req_rslt,
|
98 |
|
|
-- rx mappings
|
99 |
|
|
data_in_clk => clk,
|
100 |
|
|
reset => reset,
|
101 |
|
|
data_in => data_in,
|
102 |
|
|
data_in_valid => data_in_valid,
|
103 |
|
|
data_in_last => data_in_last,
|
104 |
|
|
-- tx mappings
|
105 |
|
|
mac_tx_req => mac_tx_req,
|
106 |
|
|
mac_tx_granted => mac_tx_granted,
|
107 |
|
|
data_out_clk => clk,
|
108 |
|
|
data_out_ready => data_out_ready,
|
109 |
4 |
pjf |
data_out_valid => data_out_valid,
|
110 |
|
|
data_out_first => data_out_first,
|
111 |
2 |
pjf |
data_out_last => data_out_last,
|
112 |
|
|
data_out => data_out,
|
113 |
|
|
-- system mappings
|
114 |
|
|
our_mac_address => our_mac_address,
|
115 |
|
|
our_ip_address => our_ip_address,
|
116 |
|
|
req_count => req_count
|
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 |
|
|
-- hold reset state for 100 ns.
|
133 |
|
|
wait for 100 ns;
|
134 |
|
|
|
135 |
|
|
our_ip_address <= x"c0a80509"; -- 192.168.5.9
|
136 |
|
|
our_mac_address <= x"002320212223";
|
137 |
|
|
mac_tx_granted <= '1'; -- FIXME 0
|
138 |
|
|
|
139 |
|
|
reset <= '1';
|
140 |
|
|
wait for clk_period*10;
|
141 |
|
|
reset <= '0';
|
142 |
|
|
wait for clk_period*5;
|
143 |
|
|
|
144 |
|
|
assert mac_tx_req = '0' report "mac_tx_req asserted on reset";
|
145 |
|
|
|
146 |
|
|
-- insert stimulus here
|
147 |
|
|
arp_req_req.lookup_req <= '0';
|
148 |
|
|
arp_req_req.ip <= (others => '0');
|
149 |
|
|
data_out_ready <= '1';
|
150 |
|
|
|
151 |
|
|
report "T1: Send an ARP request: who has 192.168.5.8? Tell 192.168.5.1";
|
152 |
|
|
data_in_valid <= '1';
|
153 |
|
|
-- dst MAC (bc)
|
154 |
|
|
data_in <= x"ff"; wait for clk_period;
|
155 |
|
|
data_in <= x"ff"; wait for clk_period;
|
156 |
|
|
data_in <= x"ff"; wait for clk_period;
|
157 |
|
|
data_in <= x"ff"; wait for clk_period;
|
158 |
|
|
data_in <= x"ff"; wait for clk_period;
|
159 |
|
|
data_in <= x"ff"; wait for clk_period;
|
160 |
|
|
-- src MAC
|
161 |
|
|
data_in <= x"00"; wait for clk_period;
|
162 |
|
|
data_in <= x"23"; wait for clk_period;
|
163 |
|
|
data_in <= x"18"; wait for clk_period;
|
164 |
|
|
data_in <= x"29"; wait for clk_period;
|
165 |
|
|
data_in <= x"26"; wait for clk_period;
|
166 |
|
|
data_in <= x"7c"; wait for clk_period;
|
167 |
|
|
-- type
|
168 |
|
|
data_in <= x"08"; wait for clk_period;
|
169 |
|
|
data_in <= x"06"; wait for clk_period;
|
170 |
|
|
-- HW type
|
171 |
|
|
data_in <= x"00"; wait for clk_period;
|
172 |
|
|
data_in <= x"01"; wait for clk_period;
|
173 |
|
|
-- Protocol type
|
174 |
|
|
data_in <= x"08"; wait for clk_period;
|
175 |
|
|
data_in <= x"00"; wait for clk_period;
|
176 |
|
|
-- HW size
|
177 |
|
|
data_in <= x"06"; wait for clk_period;
|
178 |
|
|
-- protocol size
|
179 |
|
|
data_in <= x"04"; wait for clk_period;
|
180 |
|
|
-- Opcode
|
181 |
|
|
data_in <= x"00"; wait for clk_period;
|
182 |
|
|
data_in <= x"01"; wait for clk_period;
|
183 |
|
|
-- Sender MAC
|
184 |
|
|
data_in <= x"00"; wait for clk_period;
|
185 |
|
|
data_in <= x"23"; wait for clk_period;
|
186 |
|
|
data_in <= x"18"; wait for clk_period;
|
187 |
|
|
data_in <= x"29"; wait for clk_period;
|
188 |
|
|
data_in <= x"26"; wait for clk_period;
|
189 |
|
|
data_in <= x"7c"; wait for clk_period;
|
190 |
|
|
-- Sender IP
|
191 |
|
|
data_in <= x"c0"; wait for clk_period;
|
192 |
|
|
data_in <= x"a8"; wait for clk_period;
|
193 |
|
|
data_in <= x"05"; wait for clk_period;
|
194 |
|
|
data_in <= x"01"; wait for clk_period;
|
195 |
|
|
-- Target MAC
|
196 |
|
|
data_in <= x"00"; wait for clk_period;
|
197 |
|
|
data_in <= x"00"; wait for clk_period;
|
198 |
|
|
data_in <= x"00"; wait for clk_period;
|
199 |
|
|
data_in <= x"00"; wait for clk_period;
|
200 |
|
|
data_in <= x"00"; wait for clk_period;
|
201 |
|
|
data_in <= x"00"; wait for clk_period;
|
202 |
|
|
-- Target IP
|
203 |
|
|
data_in <= x"c0"; wait for clk_period;
|
204 |
|
|
data_in <= x"a8"; wait for clk_period;
|
205 |
|
|
data_in <= x"05"; wait for clk_period;
|
206 |
|
|
data_in <= x"09"; wait for clk_period;
|
207 |
|
|
data_in <= x"00"; wait for clk_period;
|
208 |
|
|
data_in <= x"00"; wait for clk_period;
|
209 |
|
|
data_in <= x"00"; wait for clk_period;
|
210 |
|
|
data_in_last <= '1';
|
211 |
|
|
data_in <= x"00"; wait for clk_period;
|
212 |
|
|
data_in_last <= '0';
|
213 |
|
|
data_in_valid <= '0';
|
214 |
|
|
|
215 |
|
|
-- check tx arbitration signals
|
216 |
|
|
|
217 |
|
|
assert mac_tx_req = '1' report "T1: mac_tx_req not set";
|
218 |
|
|
|
219 |
|
|
-- ready to tx
|
220 |
|
|
data_out_ready <= '1';
|
221 |
|
|
mac_tx_granted <= '1';
|
222 |
|
|
wait for clk_period*10;
|
223 |
|
|
data_out_ready <= '0';
|
224 |
|
|
wait for clk_period*2;
|
225 |
|
|
data_out_ready <= '1';
|
226 |
|
|
wait for clk_period*50;
|
227 |
|
|
|
228 |
|
|
report "T2: Send another ARP request: who has 192.168.5.8? Tell 192.168.5.1, holding off transmitter";
|
229 |
|
|
data_out_ready <= '0';
|
230 |
|
|
data_in_valid <= '1';
|
231 |
|
|
-- dst MAC (bc)
|
232 |
|
|
data_in <= x"ff"; wait for clk_period;
|
233 |
|
|
data_in <= x"ff"; wait for clk_period;
|
234 |
|
|
data_in <= x"ff"; wait for clk_period;
|
235 |
|
|
data_in <= x"ff"; wait for clk_period;
|
236 |
|
|
data_in <= x"ff"; wait for clk_period;
|
237 |
|
|
data_in <= x"ff"; wait for clk_period;
|
238 |
|
|
-- src MAC
|
239 |
|
|
data_in <= x"00"; wait for clk_period;
|
240 |
|
|
data_in <= x"23"; wait for clk_period;
|
241 |
|
|
data_in <= x"18"; wait for clk_period;
|
242 |
|
|
data_in <= x"29"; wait for clk_period;
|
243 |
|
|
data_in <= x"26"; wait for clk_period;
|
244 |
|
|
data_in <= x"7c"; wait for clk_period;
|
245 |
|
|
-- type
|
246 |
|
|
data_in <= x"08"; wait for clk_period;
|
247 |
|
|
data_in <= x"06"; wait for clk_period;
|
248 |
|
|
-- HW type
|
249 |
|
|
data_in <= x"00"; wait for clk_period;
|
250 |
|
|
data_in <= x"01"; wait for clk_period;
|
251 |
|
|
-- Protocol type
|
252 |
|
|
data_in <= x"08"; wait for clk_period;
|
253 |
|
|
data_in <= x"00"; wait for clk_period;
|
254 |
|
|
-- HW size
|
255 |
|
|
data_in <= x"06"; wait for clk_period;
|
256 |
|
|
-- protocol size
|
257 |
|
|
data_in <= x"04"; wait for clk_period;
|
258 |
|
|
-- Opcode
|
259 |
|
|
data_in <= x"00"; wait for clk_period;
|
260 |
|
|
data_in <= x"01"; wait for clk_period;
|
261 |
|
|
-- Sender MAC
|
262 |
|
|
data_in <= x"00"; wait for clk_period;
|
263 |
|
|
data_in <= x"23"; wait for clk_period;
|
264 |
|
|
data_in <= x"18"; wait for clk_period;
|
265 |
|
|
data_in <= x"29"; wait for clk_period;
|
266 |
|
|
data_in <= x"26"; wait for clk_period;
|
267 |
|
|
data_in <= x"7c"; wait for clk_period;
|
268 |
|
|
-- Sender IP
|
269 |
|
|
data_in <= x"c0"; wait for clk_period;
|
270 |
|
|
data_in <= x"a8"; wait for clk_period;
|
271 |
|
|
data_in <= x"05"; wait for clk_period;
|
272 |
|
|
data_in <= x"01"; wait for clk_period;
|
273 |
|
|
-- Target MAC
|
274 |
|
|
data_in <= x"00"; wait for clk_period;
|
275 |
|
|
data_in <= x"00"; wait for clk_period;
|
276 |
|
|
data_in <= x"00"; wait for clk_period;
|
277 |
|
|
data_in <= x"00"; wait for clk_period;
|
278 |
|
|
data_in <= x"00"; wait for clk_period;
|
279 |
|
|
data_in <= x"00"; wait for clk_period;
|
280 |
|
|
-- Target IP
|
281 |
|
|
data_in <= x"c0"; wait for clk_period;
|
282 |
|
|
data_in <= x"a8"; wait for clk_period;
|
283 |
|
|
data_in <= x"05"; wait for clk_period;
|
284 |
|
|
data_in <= x"09"; wait for clk_period;
|
285 |
|
|
data_in <= x"00"; wait for clk_period;
|
286 |
|
|
data_in <= x"00"; wait for clk_period;
|
287 |
|
|
data_in <= x"00"; wait for clk_period;
|
288 |
|
|
data_in_last <= '1';
|
289 |
|
|
data_in <= x"00"; wait for clk_period;
|
290 |
|
|
data_in_last <= '0';
|
291 |
|
|
data_in_valid <= '0';
|
292 |
|
|
|
293 |
|
|
-- ready to tx
|
294 |
|
|
wait for clk_period*10;
|
295 |
|
|
data_out_ready <= '1';
|
296 |
|
|
|
297 |
|
|
wait for clk_period*50;
|
298 |
|
|
|
299 |
|
|
-- Send a request for the IP that is already cached
|
300 |
|
|
arp_req_req.ip <= x"c0a80501";
|
301 |
|
|
arp_req_req.lookup_req <= '1';
|
302 |
|
|
wait for clk_period;
|
303 |
|
|
arp_req_req.lookup_req <= '0';
|
304 |
|
|
|
305 |
|
|
wait for clk_period*50;
|
306 |
|
|
|
307 |
|
|
-- Send a request for the IP that is not cached
|
308 |
|
|
arp_req_req.ip <= x"c0a80503";
|
309 |
|
|
arp_req_req.lookup_req <= '1';
|
310 |
|
|
wait for clk_period;
|
311 |
|
|
arp_req_req.lookup_req <= '0';
|
312 |
|
|
wait for clk_period*80;
|
313 |
|
|
-- Send the reply
|
314 |
|
|
data_out_ready <= '1';
|
315 |
|
|
|
316 |
|
|
report "T3: Send an ARP reply: 192.168.5.3 has mac 02:12:03:23:04:54";
|
317 |
|
|
data_in_valid <= '1';
|
318 |
|
|
-- dst MAC (bc)
|
319 |
|
|
data_in <= x"ff"; wait for clk_period;
|
320 |
|
|
data_in <= x"ff"; wait for clk_period;
|
321 |
|
|
data_in <= x"ff"; wait for clk_period;
|
322 |
|
|
data_in <= x"ff"; wait for clk_period;
|
323 |
|
|
data_in <= x"ff"; wait for clk_period;
|
324 |
|
|
data_in <= x"ff"; wait for clk_period;
|
325 |
|
|
-- src MAC
|
326 |
|
|
data_in <= x"02"; wait for clk_period;
|
327 |
|
|
data_in <= x"12"; wait for clk_period;
|
328 |
|
|
data_in <= x"03"; wait for clk_period;
|
329 |
|
|
data_in <= x"23"; wait for clk_period;
|
330 |
|
|
data_in <= x"04"; wait for clk_period;
|
331 |
|
|
data_in <= x"54"; wait for clk_period;
|
332 |
|
|
-- type
|
333 |
|
|
data_in <= x"08"; wait for clk_period;
|
334 |
|
|
data_in <= x"06"; wait for clk_period;
|
335 |
|
|
-- HW type
|
336 |
|
|
data_in <= x"00"; wait for clk_period;
|
337 |
|
|
data_in <= x"01"; wait for clk_period;
|
338 |
|
|
-- Protocol type
|
339 |
|
|
data_in <= x"08"; wait for clk_period;
|
340 |
|
|
data_in <= x"00"; wait for clk_period;
|
341 |
|
|
-- HW size
|
342 |
|
|
data_in <= x"06"; wait for clk_period;
|
343 |
|
|
-- protocol size
|
344 |
|
|
data_in <= x"04"; wait for clk_period;
|
345 |
|
|
-- Opcode
|
346 |
|
|
data_in <= x"00"; wait for clk_period;
|
347 |
|
|
data_in <= x"02"; wait for clk_period;
|
348 |
|
|
-- Sender MAC
|
349 |
|
|
data_in <= x"02"; wait for clk_period;
|
350 |
|
|
data_in <= x"12"; wait for clk_period;
|
351 |
|
|
data_in <= x"03"; wait for clk_period;
|
352 |
|
|
data_in <= x"23"; wait for clk_period;
|
353 |
|
|
data_in <= x"04"; wait for clk_period;
|
354 |
|
|
data_in <= x"54"; wait for clk_period;
|
355 |
|
|
-- Sender IP
|
356 |
|
|
data_in <= x"c0"; wait for clk_period;
|
357 |
|
|
data_in <= x"a8"; wait for clk_period;
|
358 |
|
|
data_in <= x"05"; wait for clk_period;
|
359 |
|
|
data_in <= x"03"; wait for clk_period;
|
360 |
|
|
-- Target MAC
|
361 |
|
|
data_in <= x"00"; wait for clk_period;
|
362 |
|
|
data_in <= x"23"; wait for clk_period;
|
363 |
|
|
data_in <= x"20"; wait for clk_period;
|
364 |
|
|
data_in <= x"21"; wait for clk_period;
|
365 |
|
|
data_in <= x"22"; wait for clk_period;
|
366 |
|
|
data_in <= x"23"; wait for clk_period;
|
367 |
|
|
-- Target IP
|
368 |
|
|
data_in <= x"c0"; wait for clk_period;
|
369 |
|
|
data_in <= x"a8"; wait for clk_period;
|
370 |
|
|
data_in <= x"05"; wait for clk_period;
|
371 |
|
|
data_in <= x"09"; wait for clk_period;
|
372 |
|
|
data_in <= x"00"; wait for clk_period;
|
373 |
|
|
data_in <= x"00"; wait for clk_period;
|
374 |
|
|
data_in <= x"00"; wait for clk_period;
|
375 |
|
|
data_in_last <= '1';
|
376 |
|
|
data_in <= x"00"; wait for clk_period;
|
377 |
|
|
data_in_last <= '0';
|
378 |
|
|
data_in_valid <= '0';
|
379 |
|
|
|
380 |
|
|
report "--- end of tests ---";
|
381 |
|
|
wait;
|
382 |
|
|
end process;
|
383 |
|
|
|
384 |
|
|
END;
|