ASIC/FPGA Design and Verification Out Source Services
IP TTL filter digital design, implemented in VHDL.
-
This project implements an IP TTL filter in hardware. If an IPV4
packet is identified, the DUT checks its TTL field. Based on previous values of TTL in former packets,
the machine decides if the packet is spoofed or not. The main page
of this
project.;
-
This page explains how I randomize the delay between packet injections to the DUT. To generate
random numbers from within the VHDL test-bench, I
used a random function in the following way.
...
library my_lib;
use my_lib.my_package.all;
...
signal rand_packet_delay : std_logic_vector(3 downto 0) := "1000";
signal rand_packet_delayi: integer;
...
rand_packet_delay <= f_my_rand
f_my_rand
(4, rand_packet_delay);
--write(my_line, rand_packet_delay'path_name);
--write(my_line, string'(" "));
--hwrite(my_line, rand_packet_delay);
--write(my_line, string'(" "));
--write(my_line, now);
--writeline(output, my_line);
--packet send ended
if(unsigned(rand_packet_delay) > 3) then
rand_packet_delayi <= conv_integer(rand_packet_delay);
else
rand_packet_delayi <= conv_integer(rand_packet_delay) + 3;
end if;
for j in 1 to rand_packet_delayi loop
wait until rx_clk'event and rx_clk = '1';
end loop;
-
Recently I have improved the random generation using c code and VHPI.
First some
links
, which show simple examples of
c code interface for GHDL.
VHDL
...
--small changes during average calculation (0..3)
gen_rand := std_logic_vector(
to_unsigned(g_rand_int_c(sim_seed, 4), 4)
);
...
c code
...
int g_rand_int_c(int seed, int Pmax) {
int rnum;
if(srand_f) {
srand( (unsigned)seed);
srand_f = 0;
}
rnum = rand() % Pmax;
return rnum;
}
...
-
Controlling the seed. In the test-bench the seed is set by the following
vhdl line:
variable sim_seed : integer :=23053; --controlled from script
Note: it may appear more than once in the VHDL bench. The c code just do
the "seed operation"
just once.
Generating a new seed can be done from the makefile:
make rnd
The makefile is merely invoking the following simple script:
#!/bin/bash
r=$RANDOM
s=" variable sim_seed : integer :="${r}"; --controlled from script"
sed -i "s/variable sim_seed.*integer.*controlled from script/${s}/" $1
-
For more details on this project, please send an e-mail
and put in the subject:
IP TTL filter.
|