From cd55d6798c4bbc5198e8d66e5d13cc415e24eaed Mon Sep 17 00:00:00 2001
From: Eric Kooistra <kooistra@astron.nl>
Date: Fri, 26 Nov 2021 10:31:22 +0100
Subject: [PATCH] Added header verification functions for statistics offload
 and beamlet output.

---
 .../libraries/sdp/tb/vhdl/tb_sdp_pkg.vhd      | 174 ++++++++++++++++++
 1 file changed, 174 insertions(+)
 create mode 100644 applications/lofar2/libraries/sdp/tb/vhdl/tb_sdp_pkg.vhd

diff --git a/applications/lofar2/libraries/sdp/tb/vhdl/tb_sdp_pkg.vhd b/applications/lofar2/libraries/sdp/tb/vhdl/tb_sdp_pkg.vhd
new file mode 100644
index 0000000000..34f1697b53
--- /dev/null
+++ b/applications/lofar2/libraries/sdp/tb/vhdl/tb_sdp_pkg.vhd
@@ -0,0 +1,174 @@
+-------------------------------------------------------------------------------
+--
+-- Copyright 2020
+-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
+-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+--     http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-------------------------------------------------------------------------------
+
+-------------------------------------------------------------------------------
+--
+-- Author: E. Kooistra
+-- Purpose: 
+-- . This package contains specific constants, functions for sdp test benches.
+-- Description:
+-------------------------------------------------------------------------------
+LIBRARY IEEE, common_lib;
+USE IEEE.std_logic_1164.ALL;
+USE common_lib.common_pkg.ALL;
+USE work.sdp_pkg.ALL;
+
+PACKAGE tb_sdp_pkg is
+  -----------------------------------------------------------------------------
+  -- Statistics offload
+  -----------------------------------------------------------------------------
+  FUNCTION func_sdp_verify_stat_header(g_statistics_type : STRING; in_hdr, exp_hdr : t_sdp_stat_header; sdp_info : t_sdp_info; exp_bsn : NATURAL) RETURN BOOLEAN;
+
+  -----------------------------------------------------------------------------
+  -- Beamlet output via 10GbE to CEP (= central processor)
+  -----------------------------------------------------------------------------
+  FUNCTION func_sdp_verify_cep_header(in_hdr, exp_hdr : t_sdp_cep_header; sdp_info : t_sdp_info; exp_bsn : NATURAL) RETURN BOOLEAN;
+
+
+END PACKAGE tb_sdp_pkg;
+
+PACKAGE BODY tb_sdp_pkg IS
+
+  FUNCTION func_sdp_verify_stat_header(g_statistics_type : STRING; in_hdr, exp_hdr : t_sdp_stat_header; sdp_info : t_sdp_info; exp_bsn : NATURAL) RETURN BOOLEAN IS
+  BEGIN
+    -- eth header
+    ASSERT in_hdr.eth.dst_mac        = exp_hdr.eth.dst_mac  REPORT "Wrong " & g_statistics_type & " eth.dst_mac"  SEVERITY ERROR;
+    ASSERT in_hdr.eth.src_mac        = exp_hdr.eth.src_mac  REPORT "Wrong " & g_statistics_type & " eth.src_mac"  SEVERITY ERROR;
+    ASSERT in_hdr.eth.eth_type       = exp_hdr.eth.eth_type REPORT "Wrong " & g_statistics_type & " eth.eth_type" SEVERITY ERROR;
+
+    -- ip header
+    ASSERT in_hdr.ip.version         = exp_hdr.ip.version         REPORT "Wrong " & g_statistics_type & " ip.version"         SEVERITY ERROR;
+    ASSERT in_hdr.ip.header_length   = exp_hdr.ip.header_length   REPORT "Wrong " & g_statistics_type & " ip.header_length"   SEVERITY ERROR;
+    ASSERT in_hdr.ip.services        = exp_hdr.ip.services        REPORT "Wrong " & g_statistics_type & " ip.services"        SEVERITY ERROR;
+    ASSERT in_hdr.ip.total_length    = exp_hdr.ip.total_length    REPORT "Wrong " & g_statistics_type & " ip.total_length"    SEVERITY ERROR;
+    ASSERT in_hdr.ip.identification  = exp_hdr.ip.identification  REPORT "Wrong " & g_statistics_type & " ip.identification"  SEVERITY ERROR;
+    ASSERT in_hdr.ip.flags           = exp_hdr.ip.flags           REPORT "Wrong " & g_statistics_type & " ip.flags"           SEVERITY ERROR;
+    ASSERT in_hdr.ip.fragment_offset = exp_hdr.ip.fragment_offset REPORT "Wrong " & g_statistics_type & " ip.fragment_offset" SEVERITY ERROR;
+    ASSERT in_hdr.ip.time_to_live    = exp_hdr.ip.time_to_live    REPORT "Wrong " & g_statistics_type & " ip.time_to_live"    SEVERITY ERROR;
+    ASSERT in_hdr.ip.protocol        = exp_hdr.ip.protocol        REPORT "Wrong " & g_statistics_type & " ip.protocol"        SEVERITY ERROR;
+    ASSERT in_hdr.ip.header_checksum = exp_hdr.ip.header_checksum REPORT "Wrong " & g_statistics_type & " ip.header_checksum" SEVERITY ERROR;
+    ASSERT in_hdr.ip.src_ip_addr     = exp_hdr.ip.src_ip_addr     REPORT "Wrong " & g_statistics_type & " ip.src_ip_addr"     SEVERITY ERROR;
+    ASSERT in_hdr.ip.dst_ip_addr     = exp_hdr.ip.dst_ip_addr     REPORT "Wrong " & g_statistics_type & " ip.dst_ip_addr"     SEVERITY ERROR;
+
+    -- udp header
+    ASSERT in_hdr.udp.src_port       = exp_hdr.udp.src_port     REPORT "Wrong " & g_statistics_type & " udp.src_port"     SEVERITY ERROR;
+    ASSERT in_hdr.udp.dst_port       = exp_hdr.udp.dst_port     REPORT "Wrong " & g_statistics_type & " udp.dst_port"     SEVERITY ERROR;
+    ASSERT in_hdr.udp.total_length   = exp_hdr.udp.total_length REPORT "Wrong " & g_statistics_type & " udp.total_length" SEVERITY ERROR;
+    ASSERT in_hdr.udp.checksum       = exp_hdr.udp.checksum     REPORT "Wrong " & g_statistics_type & " udp.checksum"     SEVERITY ERROR;
+
+    -- app header
+    ASSERT in_hdr.app.sdp_marker                              = exp_hdr.app.sdp_marker     REPORT "Wrong " & g_statistics_type & " app.sdp_marker"         SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_version_id                          = exp_hdr.app.sdp_version_id REPORT "Wrong " & g_statistics_type & " app.sdp_version_id"     SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_observation_id                      = sdp_info.observation_id    REPORT "Wrong " & g_statistics_type & " app.sdp_observation_id" SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_station_id                          = sdp_info.station_id        REPORT "Wrong " & g_statistics_type & " app.sdp_station_id"     SEVERITY ERROR;
+
+    ASSERT in_hdr.app.sdp_source_info_antenna_band_id         = slv(sdp_info.antenna_band_index)                        REPORT "Wrong " & g_statistics_type & " app.sdp_source_info_antenna_band_id"         SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_source_info_nyquist_zone_id         =     sdp_info.nyquist_zone_index                         REPORT "Wrong " & g_statistics_type & " app.sdp_source_info_nyquist_zone_id"         SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_source_info_f_adc                   = slv(sdp_info.f_adc)                                     REPORT "Wrong " & g_statistics_type & " app.sdp_source_info_f_adc"                   SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_source_info_fsub_type               = slv(sdp_info.fsub_type)                                 REPORT "Wrong " & g_statistics_type & " app.sdp_source_info_fsub_type"               SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_source_info_payload_error           =     exp_hdr.app.sdp_source_info_payload_error           REPORT "Wrong " & g_statistics_type & " app.sdp_source_info_payload_error"           SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_source_info_beam_repositioning_flag = slv(sdp_info.beam_repositioning_flag)                   REPORT "Wrong " & g_statistics_type & " app.sdp_source_info_beam_repositioning_flag" SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_source_info_subband_calibrated_flag =     exp_hdr.app.sdp_source_info_subband_calibrated_flag REPORT "Wrong " & g_statistics_type & " app.sdp_source_info_subband_calibrated_flag" SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_source_info_reserved                =     exp_hdr.app.sdp_source_info_reserved                REPORT "Wrong " & g_statistics_type & " app.sdp_source_info_reserved"                SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_source_info_gn_id                   =     exp_hdr.app.sdp_source_info_gn_id                   REPORT "Wrong " & g_statistics_type & " app.sdp_source_info_gn_id"                   SEVERITY ERROR;
+
+    ASSERT in_hdr.app.sdp_reserved                            = exp_hdr.app.sdp_reserved                         REPORT "Wrong " & g_statistics_type & " app.sdp_reserved"                         SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_integration_interval                = exp_hdr.app.sdp_integration_interval             REPORT "Wrong " & g_statistics_type & " app.sdp_integration_interval"             SEVERITY ERROR;
+
+    -- . sdp_data_id word and fields per g_statistics_type
+    ASSERT in_hdr.app.sdp_data_id                             = exp_hdr.app.sdp_data_id                          REPORT "Wrong " & g_statistics_type & " app.sdp_data_id"                          SEVERITY ERROR;
+    IF g_statistics_type = "SST" THEN
+      ASSERT in_hdr.app.sdp_data_id_sst_signal_input_index    = exp_hdr.app.sdp_data_id_sst_signal_input_index   REPORT "Wrong " & g_statistics_type & " app.sdp_data_id_sst_signal_input_index"   SEVERITY ERROR;
+    ELSIF g_statistics_type = "BST" THEN
+      ASSERT in_hdr.app.sdp_data_id_bst_beamlet_index         = exp_hdr.app.sdp_data_id_bst_beamlet_index        REPORT "Wrong " & g_statistics_type & " app.sdp_data_id_bst_beamlet_index"        SEVERITY ERROR;
+    ELSIF g_statistics_type = "XST" THEN
+      ASSERT in_hdr.app.sdp_data_id_xst_subband_index         = exp_hdr.app.sdp_data_id_xst_subband_index        REPORT "Wrong " & g_statistics_type & " app.sdp_data_id_xst_subband_index"        SEVERITY ERROR;
+      ASSERT in_hdr.app.sdp_data_id_xst_signal_input_A_index  = exp_hdr.app.sdp_data_id_xst_signal_input_A_index REPORT "Wrong " & g_statistics_type & " app.sdp_data_id_xst_signal_input_A_index" SEVERITY ERROR;
+      ASSERT in_hdr.app.sdp_data_id_xst_signal_input_B_index  = exp_hdr.app.sdp_data_id_xst_signal_input_B_index REPORT "Wrong " & g_statistics_type & " app.sdp_data_id_xst_signal_input_B_index" SEVERITY ERROR;
+    ELSE
+      REPORT "Wrong " & g_statistics_type SEVERITY FAILURE;
+    END IF;
+
+    ASSERT in_hdr.app.sdp_nof_signal_inputs                   = exp_hdr.app.sdp_nof_signal_inputs                REPORT "Wrong " & g_statistics_type & " app.sdp_nof_signal_inputs"                SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_nof_bytes_per_statistics            = exp_hdr.app.sdp_nof_bytes_per_statistics         REPORT "Wrong " & g_statistics_type & " app.sdp_nof_bytes_per_statistics"         SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_nof_statistics_per_packet           = exp_hdr.app.sdp_nof_statistics_per_packet        REPORT "Wrong " & g_statistics_type & " app.sdp_nof_statistics_per_packet"        SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_block_period                        = sdp_info.block_period                            REPORT "Wrong " & g_statistics_type & " app.sdp_block_period"                     SEVERITY ERROR;
+
+    -- . TODO see L2SDP-210: bsn is not fully received (bit 0-15 is missing) because 32 bit allignment not working in dp_offload_rx.vhd.
+    --ASSERT in_hdr.app.dp_bsn = TO_UVEC(exp_bsn, 64) REPORT "Wrong " & g_statistics_type & " app.dp_bsn" SEVERITY ERROR;
+    RETURN TRUE;
+  END func_sdp_verify_stat_header;
+
+
+  FUNCTION func_sdp_verify_cep_header(in_hdr, exp_hdr : t_sdp_cep_header; sdp_info : t_sdp_info; exp_bsn : NATURAL) RETURN BOOLEAN IS
+  BEGIN
+    -- eth header
+    ASSERT in_hdr.eth.dst_mac        = exp_hdr.eth.dst_mac  REPORT "Wrong beamlet eth.dst_mac"  SEVERITY ERROR;
+    ASSERT in_hdr.eth.src_mac        = exp_hdr.eth.src_mac  REPORT "Wrong beamlet eth.src_mac"  SEVERITY ERROR;
+    ASSERT in_hdr.eth.eth_type       = exp_hdr.eth.eth_type REPORT "Wrong beamlet eth.eth_type" SEVERITY ERROR;
+
+    -- ip header
+    ASSERT in_hdr.ip.version         = exp_hdr.ip.version         REPORT "Wrong beamlet ip.version"         SEVERITY ERROR;
+    ASSERT in_hdr.ip.header_length   = exp_hdr.ip.header_length   REPORT "Wrong beamlet ip.header_length"   SEVERITY ERROR;
+    ASSERT in_hdr.ip.services        = exp_hdr.ip.services        REPORT "Wrong beamlet ip.services"        SEVERITY ERROR;
+    ASSERT in_hdr.ip.total_length    = exp_hdr.ip.total_length    REPORT "Wrong beamlet ip.total_length"    SEVERITY ERROR;
+    ASSERT in_hdr.ip.identification  = exp_hdr.ip.identification  REPORT "Wrong beamlet ip.identification"  SEVERITY ERROR;
+    ASSERT in_hdr.ip.flags           = exp_hdr.ip.flags           REPORT "Wrong beamlet ip.flags"           SEVERITY ERROR;
+    ASSERT in_hdr.ip.fragment_offset = exp_hdr.ip.fragment_offset REPORT "Wrong beamlet ip.fragment_offset" SEVERITY ERROR;
+    ASSERT in_hdr.ip.time_to_live    = exp_hdr.ip.time_to_live    REPORT "Wrong beamlet ip.time_to_live"    SEVERITY ERROR;
+    ASSERT in_hdr.ip.protocol        = exp_hdr.ip.protocol        REPORT "Wrong beamlet ip.protocol"        SEVERITY ERROR;
+    ASSERT in_hdr.ip.header_checksum = exp_hdr.ip.header_checksum REPORT "Wrong beamlet ip.header_checksum" SEVERITY ERROR;
+    ASSERT in_hdr.ip.src_ip_addr     = exp_hdr.ip.src_ip_addr     REPORT "Wrong beamlet ip.src_ip_addr"     SEVERITY ERROR;
+    ASSERT in_hdr.ip.dst_ip_addr     = exp_hdr.ip.dst_ip_addr     REPORT "Wrong beamlet ip.dst_ip_addr"     SEVERITY ERROR;
+
+    -- udp header
+    ASSERT in_hdr.udp.src_port       = exp_hdr.udp.src_port     REPORT "Wrong beamlet udp.src_port"     SEVERITY ERROR;
+    ASSERT in_hdr.udp.dst_port       = exp_hdr.udp.dst_port     REPORT "Wrong beamlet udp.dst_port"     SEVERITY ERROR;
+    ASSERT in_hdr.udp.total_length   = exp_hdr.udp.total_length REPORT "Wrong beamlet udp.total_length" SEVERITY ERROR;
+    ASSERT in_hdr.udp.checksum       = exp_hdr.udp.checksum     REPORT "Wrong beamlet udp.checksum"     SEVERITY ERROR;
+
+    -- app header
+    ASSERT in_hdr.app.sdp_marker                              = exp_hdr.app.sdp_marker     REPORT "Wrong beamlet app.sdp_marker"         SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_version_id                          = exp_hdr.app.sdp_version_id REPORT "Wrong beamlet app.sdp_version_id"     SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_observation_id                      = sdp_info.observation_id    REPORT "Wrong beamlet app.sdp_observation_id" SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_station_id                          = sdp_info.station_id        REPORT "Wrong beamlet app.sdp_station_id"     SEVERITY ERROR;
+
+    ASSERT in_hdr.app.sdp_source_info_antenna_band_id    = slv(sdp_info.antenna_band_index)              REPORT "Wrong beamlet app.sdp_source_info_antenna_band_id"    SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_source_info_nyquist_zone_id    =     sdp_info.nyquist_zone_index               REPORT "Wrong beamlet app.sdp_source_info_nyquist_zone_id"    SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_source_info_f_adc              = slv(sdp_info.f_adc)                           REPORT "Wrong beamlet app.sdp_source_info_f_adc"              SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_source_info_fsub_type          = slv(sdp_info.fsub_type)                       REPORT "Wrong beamlet app.sdp_source_info_fsub_type"          SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_source_info_payload_error      =     exp_hdr.app.sdp_source_info_payload_error REPORT "Wrong beamlet app.sdp_source_info_payload_error"      SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_source_info_repositioning_flag = slv(sdp_info.beam_repositioning_flag)         REPORT "Wrong beamlet app.sdp_source_info_repositioning_flag" SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_source_info_beamlet_width      =     exp_hdr.app.sdp_source_info_beamlet_width REPORT "Wrong beamlet app.sdp_source_info_beamlet_width"      SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_source_info_gn_id              =     exp_hdr.app.sdp_source_info_gn_id         REPORT "Wrong beamlet app.sdp_source_info_gn_id"              SEVERITY ERROR;
+
+    ASSERT in_hdr.app.sdp_reserved               = exp_hdr.app.sdp_reserved               REPORT "Wrong beamlet app.sdp_reserved"               SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_beamlet_scale          = exp_hdr.app.sdp_beamlet_scale          REPORT "Wrong beamlet app.sdp_beamlet_scale"          SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_beamlet_id             = exp_hdr.app.sdp_beamlet_id             REPORT "Wrong beamlet app.sdp_beamlet_id"             SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_nof_blocks_per_packet  = exp_hdr.app.sdp_nof_blocks_per_packet  REPORT "Wrong beamlet app.sdp_nof_blocks_per_packet"  SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_nof_beamlets_per_block = exp_hdr.app.sdp_nof_beamlets_per_block REPORT "Wrong beamlet app.sdp_nof_beamlets_per_block" SEVERITY ERROR;
+    ASSERT in_hdr.app.sdp_block_period           = sdp_info.block_period                  REPORT "Wrong beamlet app.sdp_block_period"           SEVERITY ERROR;
+
+    -- . TODO see L2SDP-210: bsn is not fully received (bit 0-15 is missing) because 32 bit allignment not working in dp_offload_rx.vhd.
+    --ASSERT in_hdr.app.dp_bsn = TO_UVEC(exp_bsn, 64) REPORT "Wrong beamlet app.dp_bsn" SEVERITY ERROR;
+    RETURN TRUE;
+  END func_sdp_verify_cep_header;
+
+END tb_sdp_pkg;
-- 
GitLab