File: arp_responder_test.vhd

package info (click to toggle)
uhd 4.9.0.0%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 184,180 kB
  • sloc: cpp: 262,887; python: 112,011; ansic: 102,670; vhdl: 57,031; tcl: 19,924; xml: 8,581; makefile: 3,028; sh: 2,812; pascal: 230; javascript: 120; csh: 94; asm: 20; perl: 11
file content (185 lines) | stat: -rw-r--r-- 4,843 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
--
-- Copyright 2019 Ettus Research, A National Instruments brand
--
-- SPDX-License-Identifier: LGPL-3.0
--
-- Module: arp_responder_test
-- Description: Simulation module to check the arp_responder IP
-- Sends a request to the arp_responder and checks for the expected reply

library ieee;
use ieee.std_logic_1164.all;

library work;
use work.arp_responder;

entity arp_responder_test is
end arp_responder_test;

architecture sim of arp_responder_test is
  signal test_fail     : boolean := false;
  signal aclk          : std_logic := '0';
  signal aresetn       : std_logic;
  signal mac_addr      : std_logic_vector(47 downto 0) := X"017136E7BE02";
  signal ip_addr       : std_logic_vector(31 downto 0) := X"04030201";
  signal s_axis_tdata  : std_logic_vector(63 downto 0);
  signal s_axis_tvalid : std_logic;
  signal s_axis_tready : std_logic;
  signal s_axis_tkeep  : std_logic_vector(7 downto 0);
  signal s_axis_tlast  : std_logic;
  signal s_axis_tuser  : std_logic;
  signal m_axis_tdata  : std_logic_vector(63 downto 0);
  signal m_axis_tvalid : std_logic;
  signal m_axis_tready : std_logic;
  signal m_axis_tkeep  : std_logic_vector(7 downto 0);
  signal m_axis_tlast  : std_logic;
  signal m_axis_tuser  : std_logic;

  constant HALFCYCLE : time := 4 ns;
  constant CYCLE : time := 2*HALFCYCLE;
  constant ARP_REQUEST_VECTOR : std_logic_vector(64*8-1 downto 0) :=
      X"0000000000000000" & --Padding
      X"0000000000000000" & --Padding
      X"000000000000" & --Packet filler
      X"04030201" &   --
      X"000000000000" &
      X"020B010A" &
      X"00D00D010101" &
      X"0100" &
      X"04" &
      X"06" &
      X"0008" &
      X"0100" &
      X"0608" &
      X"00D00D010101" &
      X"FFFFFFFFFFFF";
  constant ARP_REPLY_VECTOR : std_logic_vector(64*8-1 downto 0) :=
      X"0000000000000000" & --Padding
      X"0000000000000000" & --Padding
      X"000000000000" & --Packet filler
      X"020B010A" &
      X"00D00D010101" &
      X"04030201" &   --
      X"017136E7BE02" &
      X"0200" &
      X"04" &
      X"06" &
      X"0008" &
      X"0100" &
      X"0608" &
      X"017136E7BE02" &
      X"00D00D010101";
  --Dest --6
  --Src  --6
  --Ethertype --2
  --HTYPE = 0x0001 --2
  --PTYPE = 0x0800 --2
  --HLEN  = 0x06 --1
  --PLEN  = 0x04 --1
  --OPER  = 0x0001 --2
  --SHA   = --6
  --SPA   = --4
  --THA   = --6
  --TPA   = --4
  --Need to check...
  --  ARP request to us
  --  ARP request not to us
  --  Malformed packet
begin

  process
  begin
    wait for HALFCYCLE;
    aclk <= not aclk;
  end process;

  process
  begin
    wait for CYCLE;
    aresetn <= '0';
    wait for 3*CYCLE;
    aresetn <= '1';
    s_axis_tvalid <= '0';
    s_axis_tkeep <= X"00";
    s_axis_tlast <= '0';
    s_axis_tuser <= '0';
    m_axis_tready <= '0';
    wait for CYCLE;
    for i in 0 to 7 loop
      s_axis_tdata <= ARP_REQUEST_VECTOR(64*i+63 downto 64*i);
      s_axis_tkeep <= X"FF";
      s_axis_tvalid <= '1';
      if (i = 7) then
        s_axis_tlast <= '1';
      else
        s_axis_tlast <= '0';
      end if;
      if (i >= 3) then
        s_axis_tuser <= '1';
      else
        s_axis_tuser <= '0';
      end if;
      wait for CYCLE;
      s_axis_tvalid <= '0';
      wait for 7*CYCLE;
      --wait until s_axis_tready = '1';
    end loop;
    wait for CYCLE;
    s_axis_tvalid <= '0';
    s_axis_tuser <= '0';
    wait for CYCLE;
    for i in 0 to 7 loop
      s_axis_tdata <= ARP_REQUEST_VECTOR(64*i+63 downto 64*i);
      s_axis_tkeep <= X"FF";
      s_axis_tvalid <= '1';
      if (i = 7) then
        s_axis_tlast <= '1';
      else
        s_axis_tlast <= '0';
      end if;
      wait for CYCLE;
      s_axis_tvalid <= '0';
      wait for 7*CYCLE;
      --wait until s_axis_tready = '1';
    end loop;
    wait for CYCLE;
    s_axis_tvalid <= '0';
    wait for CYCLE;
    for i in 0 to 7 loop
      m_axis_tready <= '1';
      if (m_axis_tdata /= ARP_REPLY_VECTOR(64*i+63 downto 64*i)) then
        test_fail <= true;
        report "Reply vector mismatch";
      end if;
      wait for CYCLE;
      m_axis_tready <= '0';
      wait for 7*CYCLE;
    end loop;
    wait for CYCLE;
    if (test_fail) then
      report "Test FAILED" severity failure;
    else
      report "PASS: End of test" severity failure;
    end if;
  end process;

dut : entity arp_responder
port map (
  aclk          => aclk,
  aresetn       => aresetn,
  mac_addr      => mac_addr,
  ip_addr       => ip_addr,
  s_axis_tdata  => s_axis_tdata,
  s_axis_tvalid => s_axis_tvalid,
  s_axis_tready => s_axis_tready,
  s_axis_tkeep  => s_axis_tkeep,
  s_axis_tlast  => s_axis_tlast,
  s_axis_tuser  => s_axis_tuser,
  m_axis_tdata  => m_axis_tdata,
  m_axis_tvalid => m_axis_tvalid,
  m_axis_tready => m_axis_tready,
  m_axis_tkeep  => m_axis_tkeep,
  m_axis_tlast  => m_axis_tlast,
  m_axis_tuser  => m_axis_tuser
);
end sim;