library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

library osvvm; -- Utility Library
context osvvm.OsvvmContext;

use work.rtps_package.all;
use work.user_config.all;
use work.rtps_config_package.all;
use work.rtps_test_package.all;

-- This testbench tests the input handling of parameter lists. We issue one parameter list with invalid parameter length (less than expected) 
-- and one with valid larger parameter length (extra Bytes after expected parameter end) for each of the parameters that are handled by the built-in endpoint.
-- We also issue a parameter list that is missing its sentinel.
-- The PIDs handled are:
--  * PID_PARTICIPANT_GUID
--  * PID_DOMAIN_ID
--  * PID_DOMAIN_TAG
--  * PID_PROTOCOL_VERSION
--  * PID_PARTICIPANT_LEASE_DURATION
--  * PID_BUILTIN_ENDPOINT_SET
--  * PID_DEFAULT_UNICAST_LOCATOR
--  * PID_DEFAULT_MULTICAST_LOCATOR
--  * PID_METATRAFFIC_UNICAST_LOCATOR
--  * PID_METATRAFFIC_MULTICAST_LOCATOR
--  * PID_TOPIC_NAME
--  * PID_TYPE_NAME
--  * PID_DURABILITY
--  * PID_DEADLINE
--  * PID_LIVELINESS
--  * PID_RELIABILITY
--  * PID_DESTINATION_ORDER
--  * PID_OWNERSHIP
--  * PID_PRESENTATION
--  * PID_LATENCY_BUDGET
--  * PID_ENDPOINT_GUID
--  * PID_EXPECTS_INLINE_QOS
--  * PID_DATA_MAX_SIZE_SERIALIZED
--  * PID_UNICAST_LOCATOR
--  * PID_MULTICAST_LOCATOR

entity L0_rtps_builtin_endpoint_test3 is
end entity;

architecture testbench of L0_rtps_builtin_endpoint_test3 is
    
    -- *CONSTANT DECLARATION*
    constant MAX_REMOTE_PARTICIPANTS    : natural := 11;
    type TEST_RAM_TYPE is array (0 to (MAX_REMOTE_PARTICIPANTS*PARTICIPANT_FRAME_SIZE)-1) of std_logic_vector(WORD_WIDTH-1 downto 0);
    
    -- *TYPE DECLARATION*
    type TEST_STAGE_TYPE is (IDLE, BUSY);
    
    -- *SIGNAL DECLARATION*
    signal clk, in_empty, rd_sig, last_word_in, last_word_out: std_logic := '0';
    signal reset : std_logic := '1';
    signal endpoint_wr, endpoint_full   : std_logic_vector(0 to NUM_ENDPOINTS-1) := (others => '0');
    signal data_in, data_out : std_logic_vector(WORD_WIDTH-1 downto 0) := (others => '0');
    signal stim_stage : TEST_STAGE_TYPE := IDLE;
    shared variable stimulus, reference : TEST_PACKET_TYPE := EMPTY_TEST_PACKET;
    signal packet_sent : std_logic := '0';
    signal cnt_stim : natural := 0;
    signal start : std_logic := '0';
    shared variable SB_out : work.ScoreBoardPkg_builtin_endpoint.ScoreBoardPType;
    shared variable SB_mem : work.ScoreBoardPkg_MemoryTest.ScoreBoardPType;
    signal stim_done, check_done, mem_check : std_logic := '0';
    
    -- *FUNCTION DECLARATION*
    procedure wait_on_complete is
    begin
        wait until rising_edge(packet_sent);
    end procedure;
    
begin
    
    -- Unit Under Test
    uut : entity work.rtps_builtin_endpoint(arch)
        generic map (
            MAX_REMOTE_PARTICIPANTS => MAX_REMOTE_PARTICIPANTS
        )
        port map (
            clk             => clk,
            reset           => reset,
            empty           => in_empty or packet_sent,
            rd              => rd_sig,
            data_in         => data_in,
            data_out        => data_out,
            last_word_in    => last_word_in,
            time            => TIME_ZERO,
            endpoint_full   => endpoint_full,
            endpoint_wr     => endpoint_wr,
            rtps_wr         => open,
            rtps_full       => '0',
            last_word_out   => last_word_out,
            alive           => (others => '0')
        );
    
    stimulus_prc : process
        variable sub, sub_p, sub_s      : RTPS_SUBMESSAGE_TYPE := DEFAULT_RTPS_SUBMESSAGE;
        variable RV                     : RandomPType;
        variable p0, participant        : PARTICIPANT_DATA_TYPE := DEFAULT_PARTICIPANT_DATA;
        variable e0, endpoint           : ENDPOINT_DATA_TYPE := DEFAULT_ENDPOINT_DATA;
        variable p_sn, p_snp, p_sns   : SEQUENCENUMBER_TYPE := FIRST_SEQUENCENUMBER;
        variable wr_sig                 : std_logic_vector(0 to NUM_ENDPOINTS-1) := (others => '0');
        
        -- Wrapper to use procedure as function
        impure function gen_rand_loc_2 return LOCATOR_TYPE is
            variable ret : LOCATOR_TYPE := EMPTY_LOCATOR;
        begin
            gen_rand_loc(RV, ret);
            return ret;
        end function;
        
        impure function gen_rand_entityid_2(reader : boolean) return std_logic_vector is
            variable ret : std_logic_vector(ENTITYID_WIDTH-1 downto 0) := (others => '0');
        begin
            gen_rand_entityid(RV, reader, ret);
            return ret;
        end function;
        
        procedure push_endpoint_reference is
        begin
            -- MATCH
            if (wr_sig /= (wr_sig'range => '0')) then
                endpoint.match  := MATCH;
                gen_endpoint_match_frame(endpoint, reference);
                for i in 0 to reference.length-1 loop
                    SB_out.Push(wr_sig & reference.last(i) & reference.data(i));
                end loop;
                reference := EMPTY_TEST_PACKET;
            end if;
            -- UNMATCH
            if ((not wr_sig) /= (wr_sig'range => '0')) then
                endpoint.match  := UNMATCH;
                gen_endpoint_match_frame(endpoint, reference);
                for i in 0 to reference.length-1 loop
                    SB_out.Push((not wr_sig) & reference.last(i) & reference.data(i));
                end loop;
                reference := EMPTY_TEST_PACKET;
            end if;
        end procedure;
        
        procedure push_participant_reference is
            variable wr_sig : std_logic_vector(NUM_ENDPOINTS-1 downto 0) := (others => '1');
        begin
            gen_participant_match_frame(participant, reference);
            for i in 0 to reference.length-1 loop
                SB_out.Push(wr_sig & reference.last(i) & reference.data(i));
            end loop;
            reference   := EMPTY_TEST_PACKET;
        end procedure;
        
        impure function gen_rand_guid_prefix return GUIDPREFIX_TYPE is
            variable ret : GUIDPREFIX_TYPE;
        begin
            ret := (0 => RV.RandSlv(WORD_WIDTH), 1 => RV.RandSlv(WORD_WIDTH), 2 => RV.RandSlv(WORD_WIDTH));
            return ret;
        end function;
        
        procedure start_test is
        begin
            start <= '1';
            wait until rising_edge(clk);
            start       <= '0';
            mem_check   <= '0';
            wait until rising_edge(clk);
        end procedure;
    begin
        
        assert (TEST_STRING = "TEST_CONFIG_1") report "user_config incompatible with testbench." severity FAILURE;
        
        SetAlertLogName("rtps_builtin_endpoint - Level 0 - Input Handling");
        SetAlertEnable(FAILURE, TRUE);
        SetAlertEnable(ERROR, TRUE);
        SetAlertEnable(WARNING, TRUE);
        SetLogEnable(DEBUG, FALSE);
        SetLogEnable(PASSED, FALSE);
        SetLogEnable(INFO, TRUE);
        RV.InitSeed(RV'instance_name);
        
        -- Participant RTPS Submessage
        sub                                    := DEFAULT_RTPS_SUBMESSAGE;
        sub.submessageID                       := SID_DATA;
        sub.writerId                           := ENTITYID_SPDP_BUILTIN_PARTICIPANT_ANNOUNCER;
        sub.readerId                           := ENTITYID_SPDP_BUILTIN_PARTICIPANT_DETECTOR;
        sub.flags(SUBMESSAGE_DATA_FLAG_POS)    := '1';
        
        -- Publisher Endpoint RTPS Submessage
        sub_p                                    := DEFAULT_RTPS_SUBMESSAGE;
        sub_p.submessageID                       := SID_DATA;
        sub_p.writerId                           := ENTITYID_SEDP_BUILTIN_PUBLICATIONS_ANNOUNCER;
        sub_p.readerId                           := ENTITYID_SEDP_BUILTIN_PUBLICATIONS_DETECTOR;
        sub_p.flags(SUBMESSAGE_DATA_FLAG_POS)    := '1';
        
        -- Subscriber Endpoint RTPS Submessage
        sub_s                                    := DEFAULT_RTPS_SUBMESSAGE;
        sub_s.submessageID                       := SID_DATA;
        sub_s.writerId                           := ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_ANNOUNCER;
        sub_s.readerId                           := ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_DETECTOR;
        sub_s.flags(SUBMESSAGE_DATA_FLAG_POS)    := '1';
        
        -- Participant 0
        p0.guidPrefix                   := gen_rand_guid_prefix;
        p0.nr                           := 0;
        p0.defaultUnicastLocatorList    := (numLocators => int(1,CDR_LONG_WIDTH), locator => (0 => gen_rand_loc_2, others => EMPTY_LOCATOR));
        p0.availableBuiltinEndpoints(DISC_BUILTIN_ENDPOINT_SUBSCRIPTIONS_DETECTOR) := '1';
        p0.availableBuiltinEndpoints(DISC_BUILTIN_ENDPOINT_SUBSCRIPTIONS_ANNOUNCER):= '1';
        p0.availableBuiltinEndpoints(DISC_BUILTIN_ENDPOINT_PUBLICATIONS_DETECTOR)  := '1';
        p0.availableBuiltinEndpoints(DISC_BUILTIN_ENDPOINT_PUBLICATIONS_ANNOUNCER) := '1';
        p0.expectsInlineQoS(0)  := '1';
        p0.leaseDuration        := gen_duration(10,0);
        p0.builtinEndpointQoS(0):= '1';
        
        e0.participant  := p0;
        e0.topic_name   := ENDPOINT_TOPIC(0);
        e0.type_name    := ENDPOINT_TYPE(0);
        
        Log("Initiating Test", INFO);
        mem_check   <= '1';
        stim_done   <= '0';
        start       <= '0';
        reset       <= '1';
        wait until rising_edge(clk);
        wait until rising_edge(clk);
        reset   <= '0';
        
        Log("Match Participant 0 (Used for Endpoint Matching)", INFO);
        sub.writerSN    := p_sn;
        participant     := p0;
        gen_participant_data(participant, sub.data);
        gen_sentinel(sub.data);
        gen_rtps_handler_out(sub, participant, stimulus);
        SB_mem.Push(gen_participant_mem_frame(participant));
        start_test;
        mem_check   <= '1';
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub.data    := EMPTY_TEST_PACKET;
        p_sn       := p_sn + 1;
        
        -- *PID_PARTICIPANT_GUID*
        Log("Ignore Participant 1 [Invalid PID_PARTICIPANT_GUID]", INFO);
        sub.writerSN            := p_sn;
        participant             := p0;
        participant.guidPrefix  := gen_rand_guid_prefix;
        participant.nr          := 1;
        participant.match       := UNMATCH;
        gen_participant_data(participant, sub.data, PID_PARTICIPANT_GUID, -1);
        gen_sentinel(sub.data);
        gen_rtps_handler_out(sub, participant, stimulus);
        SB_mem.Push(gen_participant_mem_frame(participant));
        start_test;
        mem_check   <= '1';
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub.data    := EMPTY_TEST_PACKET;
        p_sn       := p_sn + 1;
        
        Log("Match Participant 1 [Extra Bytes in PID_PARTICIPANT_GUID]", INFO);
        sub.writerSN            := p_sn;
        participant             := p0;
        participant.guidPrefix  := gen_rand_guid_prefix;
        participant.nr          := 1;
        participant.match       := MATCH;
        gen_participant_data(participant, sub.data, PID_PARTICIPANT_GUID, +1);
        gen_sentinel(sub.data);
        gen_rtps_handler_out(sub, participant, stimulus);
        SB_mem.Push(gen_participant_mem_frame(participant));
        start_test;
        mem_check   <= '1';
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub.data    := EMPTY_TEST_PACKET;
        p_sn       := p_sn + 1;
        
        -- *PID_DOMAIN_ID*
        Log("Ignore Participant 2 [Invalid PID_DOMAIN_ID]", INFO);
        sub.writerSN            := p_sn;
        participant             := p0;
        participant.guidPrefix  := gen_rand_guid_prefix;
        participant.nr          := 2;
        participant.match       := UNMATCH;
        gen_participant_data(participant, sub.data, PID_DOMAIN_ID, -1);
        gen_sentinel(sub.data);
        gen_rtps_handler_out(sub, participant, stimulus);
        SB_mem.Push(gen_participant_mem_frame(participant));
        start_test;
        mem_check   <= '1';
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub.data    := EMPTY_TEST_PACKET;
        p_sn       := p_sn + 1;
        
        Log("Match Participant 2 [Extra Bytes in PID_DOMAIN_ID]", INFO);
        sub.writerSN            := p_sn;
        participant             := p0;
        participant.guidPrefix  := gen_rand_guid_prefix;
        participant.nr          := 2;
        participant.match       := MATCH;
        gen_participant_data(participant, sub.data, PID_DOMAIN_ID, +1);
        gen_sentinel(sub.data);
        gen_rtps_handler_out(sub, participant, stimulus);
        SB_mem.Push(gen_participant_mem_frame(participant));
        start_test;
        mem_check   <= '1';
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub.data    := EMPTY_TEST_PACKET;
        p_sn       := p_sn + 1;
        
        -- *PID_DOMAIN_TAG*
        Log("Ignore Participant 3 [Invalid PID_DOMAIN_TAG]", INFO);
        sub.writerSN            := p_sn;
        participant             := p0;
        participant.guidPrefix  := gen_rand_guid_prefix;
        participant.nr          := 3;
        participant.match       := UNMATCH;
        gen_participant_data(participant, sub.data, PID_DOMAIN_TAG, -1);
        gen_sentinel(sub.data);
        gen_rtps_handler_out(sub, participant, stimulus);
        SB_mem.Push(gen_participant_mem_frame(participant));
        start_test;
        mem_check   <= '1';
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub.data    := EMPTY_TEST_PACKET;
        p_sn       := p_sn + 1;
        
        Log("Match Participant 3 [Extra Bytes in PID_DOMAIN_TAG]", INFO);
        sub.writerSN            := p_sn;
        participant             := p0;
        participant.guidPrefix  := gen_rand_guid_prefix;
        participant.nr          := 3;
        participant.match       := MATCH;
        gen_participant_data(participant, sub.data, PID_DOMAIN_TAG, +1);
        gen_sentinel(sub.data);
        gen_rtps_handler_out(sub, participant, stimulus);
        SB_mem.Push(gen_participant_mem_frame(participant));
        start_test;
        mem_check   <= '1';
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub.data    := EMPTY_TEST_PACKET;
        p_sn       := p_sn + 1;
        
        -- *PID_PROTOCOL_VERSION*
        Log("Ignore Participant 4 [Invalid PID_PROTOCOL_VERSION]", INFO);
        sub.writerSN            := p_sn;
        participant             := p0;
        participant.guidPrefix  := gen_rand_guid_prefix;
        participant.nr          := 4;
        participant.match       := UNMATCH;
        gen_participant_data(participant, sub.data, PID_PROTOCOL_VERSION, -1);
        gen_sentinel(sub.data);
        gen_rtps_handler_out(sub, participant, stimulus);
        SB_mem.Push(gen_participant_mem_frame(participant));
        start_test;
        mem_check   <= '1';
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub.data    := EMPTY_TEST_PACKET;
        p_sn       := p_sn + 1;
        
        Log("Match Participant 4 [Extra Bytes in PID_PROTOCOL_VERSION]", INFO);
        sub.writerSN            := p_sn;
        participant             := p0;
        participant.guidPrefix  := gen_rand_guid_prefix;
        participant.nr          := 4;
        participant.match       := MATCH;
        gen_participant_data(participant, sub.data, PID_PROTOCOL_VERSION, +1);
        gen_sentinel(sub.data);
        gen_rtps_handler_out(sub, participant, stimulus);
        SB_mem.Push(gen_participant_mem_frame(participant));
        start_test;
        mem_check   <= '1';
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub.data    := EMPTY_TEST_PACKET;
        p_sn       := p_sn + 1;
        
        -- *PID_PARTICIPANT_LEASE_DURATION*
        Log("Ignore Participant 5 [Invalid PID_PARTICIPANT_LEASE_DURATION]", INFO);
        sub.writerSN            := p_sn;
        participant             := p0;
        participant.guidPrefix  := gen_rand_guid_prefix;
        participant.nr          := 5;
        participant.match       := UNMATCH;
        gen_participant_data(participant, sub.data, PID_PARTICIPANT_LEASE_DURATION, -1);
        gen_sentinel(sub.data);
        gen_rtps_handler_out(sub, participant, stimulus);
        SB_mem.Push(gen_participant_mem_frame(participant));
        start_test;
        mem_check   <= '1';
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub.data    := EMPTY_TEST_PACKET;
        p_sn       := p_sn + 1;
        
        Log("Match Participant 5 [Extra Bytes in PID_PARTICIPANT_LEASE_DURATION]", INFO);
        sub.writerSN            := p_sn;
        participant             := p0;
        participant.guidPrefix  := gen_rand_guid_prefix;
        participant.nr          := 5;
        participant.match       := MATCH;
        gen_participant_data(participant, sub.data, PID_PARTICIPANT_LEASE_DURATION, +1);
        gen_sentinel(sub.data);
        gen_rtps_handler_out(sub, participant, stimulus);
        SB_mem.Push(gen_participant_mem_frame(participant));
        start_test;
        mem_check   <= '1';
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub.data    := EMPTY_TEST_PACKET;
        p_sn       := p_sn + 1;
        
        -- *PID_BUILTIN_ENDPOINT_SET*
        Log("Ignore Participant 6 [Invalid PID_BUILTIN_ENDPOINT_SET]", INFO);
        sub.writerSN            := p_sn;
        participant             := p0;
        participant.guidPrefix  := gen_rand_guid_prefix;
        participant.nr          := 6;
        participant.match       := UNMATCH;
        gen_participant_data(participant, sub.data, PID_BUILTIN_ENDPOINT_SET, -1);
        gen_sentinel(sub.data);
        gen_rtps_handler_out(sub, participant, stimulus);
        SB_mem.Push(gen_participant_mem_frame(participant));
        start_test;
        mem_check   <= '1';
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub.data    := EMPTY_TEST_PACKET;
        p_sn       := p_sn + 1;
        
        Log("Match Participant 6 [Extra Bytes in PID_BUILTIN_ENDPOINT_SET]", INFO);
        sub.writerSN            := p_sn;
        participant             := p0;
        participant.guidPrefix  := gen_rand_guid_prefix;
        participant.nr          := 6;
        participant.match       := MATCH;
        gen_participant_data(participant, sub.data, PID_BUILTIN_ENDPOINT_SET, +1);
        gen_sentinel(sub.data);
        gen_rtps_handler_out(sub, participant, stimulus);
        SB_mem.Push(gen_participant_mem_frame(participant));
        start_test;
        mem_check   <= '1';
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub.data    := EMPTY_TEST_PACKET;
        p_sn       := p_sn + 1;
        
        -- *PID_DEFAULT_UNICAST_LOCATOR*
        Log("Ignore Participant 7 [Invalid PID_DEFAULT_UNICAST_LOCATOR]", INFO);
        sub.writerSN            := p_sn;
        participant             := p0;
        participant.defaultUnicastLocatorList   := (numLocators => int(1,CDR_LONG_WIDTH), locator => (0 => gen_rand_loc_2, others => EMPTY_LOCATOR));
        participant.guidPrefix  := gen_rand_guid_prefix;
        participant.nr          := 7;
        participant.match       := UNMATCH;
        gen_participant_data(participant, sub.data, PID_DEFAULT_UNICAST_LOCATOR, -1);
        gen_sentinel(sub.data);
        gen_rtps_handler_out(sub, participant, stimulus);
        SB_mem.Push(gen_participant_mem_frame(participant));
        start_test;
        mem_check   <= '1';
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub.data    := EMPTY_TEST_PACKET;
        p_sn       := p_sn + 1;
        
        Log("Match Participant 7 [Extra Bytes in PID_DEFAULT_UNICAST_LOCATOR]", INFO);
        sub.writerSN            := p_sn;
        participant             := p0;
        participant.defaultUnicastLocatorList   := (numLocators => int(1,CDR_LONG_WIDTH), locator => (0 => gen_rand_loc_2, others => EMPTY_LOCATOR));
        participant.guidPrefix  := gen_rand_guid_prefix;
        participant.nr          := 7;
        participant.match       := MATCH;
        gen_participant_data(participant, sub.data, PID_DEFAULT_UNICAST_LOCATOR, +1);
        gen_sentinel(sub.data);
        gen_rtps_handler_out(sub, participant, stimulus);
        SB_mem.Push(gen_participant_mem_frame(participant));
        start_test;
        mem_check   <= '1';
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub.data    := EMPTY_TEST_PACKET;
        p_sn       := p_sn + 1;
        
        -- *PID_DEFAULT_MULTICAST_LOCATOR*
        Log("Ignore Participant 8 [Invalid PID_DEFAULT_MULTICAST_LOCATOR]", INFO);
        sub.writerSN            := p_sn;
        participant             := p0;
        participant.defaultMulticastLocatorList   := (numLocators => int(1,CDR_LONG_WIDTH), locator => (0 => gen_rand_loc_2, others => EMPTY_LOCATOR));
        participant.guidPrefix  := gen_rand_guid_prefix;
        participant.nr          := 8;
        participant.match       := UNMATCH;
        gen_participant_data(participant, sub.data, PID_DEFAULT_MULTICAST_LOCATOR, -1);
        gen_sentinel(sub.data);
        gen_rtps_handler_out(sub, participant, stimulus);
        SB_mem.Push(gen_participant_mem_frame(participant));
        start_test;
        mem_check   <= '1';
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub.data    := EMPTY_TEST_PACKET;
        p_sn       := p_sn + 1;
        
        Log("Match Participant 8 [Extra Bytes in PID_DEFAULT_MULTICAST_LOCATOR]", INFO);
        sub.writerSN            := p_sn;
        participant             := p0;
        participant.defaultMulticastLocatorList   := (numLocators => int(1,CDR_LONG_WIDTH), locator => (0 => gen_rand_loc_2, others => EMPTY_LOCATOR));
        participant.guidPrefix  := gen_rand_guid_prefix;
        participant.nr          := 8;
        participant.match       := MATCH;
        gen_participant_data(participant, sub.data, PID_DEFAULT_MULTICAST_LOCATOR, +1);
        gen_sentinel(sub.data);
        gen_rtps_handler_out(sub, participant, stimulus);
        SB_mem.Push(gen_participant_mem_frame(participant));
        start_test;
        mem_check   <= '1';
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub.data    := EMPTY_TEST_PACKET;
        p_sn       := p_sn + 1;
        
        -- *PID_METATRAFFIC_UNICAST_LOCATOR*
        Log("Ignore Participant 9 [Invalid PID_METATRAFFIC_UNICAST_LOCATOR]", INFO);
        sub.writerSN            := p_sn;
        participant             := p0;
        participant.metatrafficUnicastLocatorList   := (numLocators => int(1,CDR_LONG_WIDTH), locator => (0 => gen_rand_loc_2, others => EMPTY_LOCATOR));
        participant.guidPrefix  := gen_rand_guid_prefix;
        participant.nr          := 9;
        participant.match       := UNMATCH;
        gen_participant_data(participant, sub.data, PID_METATRAFFIC_UNICAST_LOCATOR, -1);
        gen_sentinel(sub.data);
        gen_rtps_handler_out(sub, participant, stimulus);
        SB_mem.Push(gen_participant_mem_frame(participant));
        start_test;
        mem_check   <= '1';
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub.data    := EMPTY_TEST_PACKET;
        p_sn       := p_sn + 1;
        
        Log("Match Participant 9 [Extra Bytes in PID_METATRAFFIC_UNICAST_LOCATOR]", INFO);
        sub.writerSN            := p_sn;
        participant             := p0;
        participant.metatrafficUnicastLocatorList   := (numLocators => int(1,CDR_LONG_WIDTH), locator => (0 => gen_rand_loc_2, others => EMPTY_LOCATOR));
        participant.guidPrefix  := gen_rand_guid_prefix;
        participant.nr          := 9;
        participant.match       := MATCH;
        gen_participant_data(participant, sub.data, PID_METATRAFFIC_UNICAST_LOCATOR, +1);
        gen_sentinel(sub.data);
        gen_rtps_handler_out(sub, participant, stimulus);
        SB_mem.Push(gen_participant_mem_frame(participant));
        start_test;
        mem_check   <= '1';
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub.data    := EMPTY_TEST_PACKET;
        p_sn       := p_sn + 1;
        
        -- *PID_METATRAFFIC_MULTICAST_LOCATOR*
        Log("Ignore Participant 10 [Invalid PID_METATRAFFIC_MULTICAST_LOCATOR]", INFO);
        sub.writerSN            := p_sn;
        participant             := p0;
        participant.metatrafficMulticastLocatorList   := (numLocators => int(1,CDR_LONG_WIDTH), locator => (0 => gen_rand_loc_2, others => EMPTY_LOCATOR));
        participant.guidPrefix  := gen_rand_guid_prefix;
        participant.nr          := 10;
        participant.match       := UNMATCH;
        gen_participant_data(participant, sub.data, PID_METATRAFFIC_MULTICAST_LOCATOR, -1);
        gen_sentinel(sub.data);
        gen_rtps_handler_out(sub, participant, stimulus);
        SB_mem.Push(gen_participant_mem_frame(participant));
        start_test;
        mem_check   <= '1';
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub.data    := EMPTY_TEST_PACKET;
        p_sn       := p_sn + 1;
        
        Log("Match Participant 10 [Extra Bytes in PID_METATRAFFIC_MULTICAST_LOCATOR]", INFO);
        sub.writerSN            := p_sn;
        participant             := p0;
        participant.metatrafficMulticastLocatorList   := (numLocators => int(1,CDR_LONG_WIDTH), locator => (0 => gen_rand_loc_2, others => EMPTY_LOCATOR));
        participant.guidPrefix  := gen_rand_guid_prefix;
        participant.nr          := 10;
        participant.match       := MATCH;
        gen_participant_data(participant, sub.data, PID_METATRAFFIC_MULTICAST_LOCATOR, +1);
        gen_sentinel(sub.data);
        gen_rtps_handler_out(sub, participant, stimulus);
        SB_mem.Push(gen_participant_mem_frame(participant));
        start_test;
        mem_check   <= '1';
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub.data    := EMPTY_TEST_PACKET;
        p_sn       := p_sn + 1;
        
        -- *PID_SENTINEL*
        Log("Ignore Endpoint [No PID_SENTINEL]", INFO);
        sub_p.writerSN              := p_snp;
        endpoint                    := e0;
        endpoint.reader             := FALSE;
        endpoint.entityId           := gen_rand_entityid_2(FALSE);
        gen_endpoint_data(endpoint, sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        
        -- *PID_TOPIC_NAME*
        Log("Ignore Endpoint [Invalid PID_TOPIC_NAME]", INFO);
        sub_p.writerSN      := p_snp;
        endpoint            := e0;
        endpoint.reader     := FALSE;
        endpoint.entityId   := gen_rand_entityid_2(FALSE);
        gen_endpoint_data(endpoint, sub_p.data, PID_TOPIC_NAME, -1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        
        Log("Match Endpoint [Extra Bytes in PID_TOPIC_NAME]", INFO);
        sub_p.writerSN      := p_snp;
        endpoint            := e0;
        endpoint.reader     := FALSE;
        endpoint.entityId   := gen_rand_entityid_2(FALSE);
        gen_endpoint_data(endpoint, sub_p.data, PID_TOPIC_NAME, +1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        wr_sig  := (0 => '1', 9 => '1', 10 => '1', 15 => '1', others => '0');
        push_endpoint_reference;
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        p_snp      := p_snp + 1;
        
        -- *PID_TYPE_NAME*
        Log("Ignore Endpoint [Invalid PID_TYPE_NAME]", INFO);
        sub_p.writerSN      := p_snp;
        endpoint            := e0;
        endpoint.reader     := FALSE;
        endpoint.entityId   := gen_rand_entityid_2(FALSE);
        gen_endpoint_data(endpoint, sub_p.data, PID_TYPE_NAME, -1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        
        Log("Match Endpoint [Extra Bytes in PID_TYPE_NAME]", INFO);
        sub_p.writerSN      := p_snp;
        endpoint            := e0;
        endpoint.reader     := FALSE;
        endpoint.entityId   := gen_rand_entityid_2(FALSE);
        gen_endpoint_data(endpoint, sub_p.data, PID_TYPE_NAME, +1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        wr_sig  := (0 => '1', 9 => '1', 10 => '1', 15 => '1', others => '0');
        push_endpoint_reference;
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        p_snp      := p_snp + 1;
        
        -- *PID_DURABILITY*
        Log("Ignore Endpoint [Invalid PID_DURABILITY]", INFO);
        sub_p.writerSN      := p_snp;
        endpoint            := e0;
        endpoint.reader     := FALSE;
        endpoint.entityId   := gen_rand_entityid_2(FALSE);
        gen_endpoint_data(endpoint, sub_p.data, PID_DURABILITY, -1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        
        Log("Match Endpoint [Extra Bytes in PID_DURABILITY]", INFO);
        sub_p.writerSN      := p_snp;
        endpoint            := e0;
        endpoint.reader     := FALSE;
        endpoint.entityId   := gen_rand_entityid_2(FALSE);
        gen_endpoint_data(endpoint, sub_p.data, PID_DURABILITY, +1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        wr_sig  := (0 => '1', 9 => '1', 10 => '1', 15 => '1', others => '0');
        push_endpoint_reference;
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        p_snp      := p_snp + 1;
        
        -- *PID_DEADLINE*
        Log("Ignore Endpoint [Invalid PID_DEADLINE]", INFO);
        sub_p.writerSN      := p_snp;
        endpoint            := e0;
        endpoint.reader     := FALSE;
        endpoint.entityId   := gen_rand_entityid_2(FALSE);
        gen_endpoint_data(endpoint, sub_p.data, PID_DEADLINE, -1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        
        Log("Match Endpoint [Extra Bytes in PID_DEADLINE]", INFO);
        sub_p.writerSN      := p_snp;
        endpoint            := e0;
        endpoint.reader     := FALSE;
        endpoint.entityId   := gen_rand_entityid_2(FALSE);
        gen_endpoint_data(endpoint, sub_p.data, PID_DEADLINE, +1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        wr_sig  := (0 => '1', 9 => '1', 10 => '1', 15 => '1', others => '0');
        push_endpoint_reference;
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        p_snp      := p_snp + 1;
        
        -- *PID_LIVELINESS*
        Log("Ignore Endpoint [Invalid PID_LIVELINESS]", INFO);
        sub_p.writerSN          := p_snp;
        endpoint                := e0;
        endpoint.reader         := FALSE;
        endpoint.entityId       := gen_rand_entityid_2(FALSE);
        gen_endpoint_data(endpoint, sub_p.data, PID_LIVELINESS, -1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        
        Log("Match Endpoint [Extra Bytes in PID_LIVELINESS]", INFO);
        sub_p.writerSN          := p_snp;
        endpoint                := e0;
        endpoint.reader         := FALSE;
        endpoint.entityId       := gen_rand_entityid_2(FALSE);
        gen_endpoint_data(endpoint, sub_p.data, PID_LIVELINESS, +1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        wr_sig  := (0 => '1', 9 => '1', 10 => '1', 15 => '1', others => '0');
        push_endpoint_reference;
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        p_snp      := p_snp + 1;
        
        -- *PID_RELIABILITY*
        Log("Ignore Endpoint [Invalid PID_RELIABILITY]", INFO);
        sub_p.writerSN          := p_snp;
        endpoint                := e0;
        endpoint.reader         := FALSE;
        endpoint.entityId       := gen_rand_entityid_2(FALSE);
        gen_endpoint_data(endpoint, sub_p.data, PID_RELIABILITY, -1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        
        Log("Match Endpoint [Extra Bytes in PID_RELIABILITY]", INFO);
        sub_p.writerSN          := p_snp;
        endpoint                := e0;
        endpoint.reader         := FALSE;
        endpoint.entityId       := gen_rand_entityid_2(FALSE);
        gen_endpoint_data(endpoint, sub_p.data, PID_RELIABILITY, +1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        wr_sig  := (0 => '1', 9 => '1', 10 => '1', 15 => '1', others => '0');
        push_endpoint_reference;
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        p_snp      := p_snp + 1;
        
        -- *PID_DESTINATION_ORDER*
        Log("Ignore Endpoint [Invalid PID_DESTINATION_ORDER]", INFO);
        sub_p.writerSN              := p_snp;
        endpoint                    := e0;
        endpoint.reader             := FALSE;
        endpoint.entityId           := gen_rand_entityid_2(FALSE);
        gen_endpoint_data(endpoint, sub_p.data, PID_DESTINATION_ORDER, -1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        
        Log("Match Endpoint [Extra Bytes in PID_DESTINATION_ORDER]", INFO);
        sub_p.writerSN          := p_snp;
        endpoint                := e0;
        endpoint.reader         := FALSE;
        endpoint.entityId       := gen_rand_entityid_2(FALSE);
        gen_endpoint_data(endpoint, sub_p.data, PID_DESTINATION_ORDER, +1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        wr_sig  := (0 => '1', 9 => '1', 10 => '1', 15 => '1', others => '0');
        push_endpoint_reference;
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        p_snp      := p_snp + 1;
        
        -- *PID_OWNERSHIP*
        Log("Ignore Endpoint [Invalid PID_OWNERSHIP]", INFO);
        sub_p.writerSN              := p_snp;
        endpoint                    := e0;
        endpoint.reader             := FALSE;
        endpoint.entityId           := gen_rand_entityid_2(FALSE);
        gen_endpoint_data(endpoint, sub_p.data, PID_OWNERSHIP, -1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        
        Log("Match Endpoint [Extra Bytes in PID_OWNERSHIP]", INFO);
        sub_p.writerSN          := p_snp;
        endpoint                := e0;
        endpoint.reader         := FALSE;
        endpoint.entityId       := gen_rand_entityid_2(FALSE);
        gen_endpoint_data(endpoint, sub_p.data, PID_OWNERSHIP, +1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        wr_sig  := (0 => '1', 9 => '1', 10 => '1', 15 => '1', others => '0');
        push_endpoint_reference;
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        p_snp      := p_snp + 1;
        
        -- *PID_PRESENTATION*
        Log("Ignore Endpoint [Invalid PID_PRESENTATION]", INFO);
        sub_p.writerSN              := p_snp;
        endpoint                    := e0;
        endpoint.reader             := FALSE;
        endpoint.entityId           := gen_rand_entityid_2(FALSE);
        gen_endpoint_data(endpoint, sub_p.data, PID_PRESENTATION, -1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        
        Log("Match Endpoint [Extra Bytes in PID_PRESENTATION]", INFO);
        sub_p.writerSN          := p_snp;
        endpoint                := e0;
        endpoint.reader         := FALSE;
        endpoint.entityId       := gen_rand_entityid_2(FALSE);
        gen_endpoint_data(endpoint, sub_p.data, PID_PRESENTATION, +1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        wr_sig  := (0 => '1', 9 => '1', 10 => '1', 15 => '1', others => '0');
        push_endpoint_reference;
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        p_snp      := p_snp + 1;
        
        -- *PID_LATENCY_BUDGET*
        Log("Ignore Endpoint [Invalid PID_LATENCY_BUDGET]", INFO);
        sub_p.writerSN              := p_snp;
        endpoint                    := e0;
        endpoint.reader             := FALSE;
        endpoint.entityId           := gen_rand_entityid_2(FALSE);
        gen_endpoint_data(endpoint, sub_p.data, PID_LATENCY_BUDGET, -1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        
        Log("Match Endpoint [Extra Bytes in PID_LATENCY_BUDGET]", INFO);
        sub_p.writerSN          := p_snp;
        endpoint                := e0;
        endpoint.reader         := FALSE;
        endpoint.entityId       := gen_rand_entityid_2(FALSE);
        gen_endpoint_data(endpoint, sub_p.data, PID_LATENCY_BUDGET, +1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        wr_sig  := (0 => '1', 9 => '1', 10 => '1', 15 => '1', others => '0');
        push_endpoint_reference;
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        p_snp      := p_snp + 1;
        
        -- *PID_ENDPOINT_GUID*
        Log("Ignore Endpoint [Invalid PID_ENDPOINT_GUID]", INFO);
        sub_p.writerSN              := p_snp;
        endpoint                    := e0;
        endpoint.reader             := FALSE;
        endpoint.entityId           := gen_rand_entityid_2(FALSE);
        gen_endpoint_data(endpoint, sub_p.data, PID_ENDPOINT_GUID, -1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        
        Log("Match Endpoint [Extra Bytes in PID_ENDPOINT_GUID]", INFO);
        sub_p.writerSN          := p_snp;
        endpoint                := e0;
        endpoint.reader         := FALSE;
        endpoint.entityId       := gen_rand_entityid_2(FALSE);
        gen_endpoint_data(endpoint, sub_p.data, PID_ENDPOINT_GUID, +1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        wr_sig  := (0 => '1', 9 => '1', 10 => '1', 15 => '1', others => '0');
        push_endpoint_reference;
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        p_snp      := p_snp + 1;
        
        -- *PID_EXPECTS_INLINE_QOS*
        Log("Ignore Endpoint [Invalid PID_EXPECTS_INLINE_QOS]", INFO);
        sub_p.writerSN              := p_snp;
        endpoint                    := e0;
        endpoint.reader             := FALSE;
        endpoint.entityId           := gen_rand_entityid_2(FALSE);
        gen_endpoint_data(endpoint, sub_p.data, PID_EXPECTS_INLINE_QOS, -1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        
        Log("Match Endpoint [Extra Bytes in PID_EXPECTS_INLINE_QOS]", INFO);
        sub_p.writerSN          := p_snp;
        endpoint                := e0;
        endpoint.reader         := FALSE;
        endpoint.entityId       := gen_rand_entityid_2(FALSE);
        gen_endpoint_data(endpoint, sub_p.data, PID_EXPECTS_INLINE_QOS, +1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        wr_sig  := (0 => '1', 9 => '1', 10 => '1', 15 => '1', others => '0');
        push_endpoint_reference;
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        p_snp      := p_snp + 1;
        
        -- *PID_DATA_MAX_SIZE_SERIALIZED*
        Log("Ignore Endpoint [Invalid PID_DATA_MAX_SIZE_SERIALIZED]", INFO);
        sub_p.writerSN              := p_snp;
        endpoint                    := e0;
        endpoint.reader             := FALSE;
        endpoint.entityId           := gen_rand_entityid_2(FALSE);
        endpoint.max_size_serialized:= int(65000, CDR_LONG_WIDTH);
        gen_endpoint_data(endpoint, sub_p.data, PID_DATA_MAX_SIZE_SERIALIZED, -1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        
        Log("Match Endpoint [Extra Bytes in PID_DATA_MAX_SIZE_SERIALIZED]", INFO);
        sub_p.writerSN          := p_snp;
        endpoint                := e0;
        endpoint.reader         := FALSE;
        endpoint.entityId       := gen_rand_entityid_2(FALSE);
        endpoint.max_size_serialized:= int(65000, CDR_LONG_WIDTH);
        gen_endpoint_data(endpoint, sub_p.data, PID_DATA_MAX_SIZE_SERIALIZED, +1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        wr_sig  := (0 => '1', 9 => '1', 10 => '1', 15 => '1', others => '0');
        push_endpoint_reference;
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        p_snp      := p_snp + 1;
        
        -- *PID_UNICAST_LOCATOR*
        Log("Ignore Endpoint [Invalid PID_UNICAST_LOCATOR]", INFO);
        sub_p.writerSN              := p_snp;
        endpoint                    := e0;
        endpoint.reader             := FALSE;
        endpoint.entityId           := gen_rand_entityid_2(FALSE);
        endpoint.unicastLocatorList   := (numLocators => int(1,CDR_LONG_WIDTH), locator => (0 => gen_rand_loc_2, others => EMPTY_LOCATOR));
        gen_endpoint_data(endpoint, sub_p.data, PID_UNICAST_LOCATOR, -1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        
        Log("Match Endpoint [Extra Bytes in PID_UNICAST_LOCATOR]", INFO);
        sub_p.writerSN          := p_snp;
        endpoint                := e0;
        endpoint.reader         := FALSE;
        endpoint.entityId       := gen_rand_entityid_2(FALSE);
        endpoint.unicastLocatorList   := (numLocators => int(1,CDR_LONG_WIDTH), locator => (0 => gen_rand_loc_2, others => EMPTY_LOCATOR));
        gen_endpoint_data(endpoint, sub_p.data, PID_UNICAST_LOCATOR, +1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        wr_sig  := (0 => '1', 9 => '1', 10 => '1', 15 => '1', others => '0');
        push_endpoint_reference;
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        p_snp      := p_snp + 1;
        
        -- *PID_MULTICAST_LOCATOR*
        Log("Ignore Endpoint [Invalid PID_MULTICAST_LOCATOR]", INFO);
        sub_p.writerSN              := p_snp;
        endpoint                    := e0;
        endpoint.reader             := FALSE;
        endpoint.entityId           := gen_rand_entityid_2(FALSE);
        endpoint.multicastLocatorList   := (numLocators => int(1,CDR_LONG_WIDTH), locator => (0 => gen_rand_loc_2, others => EMPTY_LOCATOR));
        gen_endpoint_data(endpoint, sub_p.data, PID_MULTICAST_LOCATOR, -1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        
        Log("Match Endpoint [Extra Bytes in PID_MULTICAST_LOCATOR]", INFO);
        sub_p.writerSN          := p_snp;
        endpoint                := e0;
        endpoint.reader         := FALSE;
        endpoint.entityId       := gen_rand_entityid_2(FALSE);
        endpoint.multicastLocatorList   := (numLocators => int(1,CDR_LONG_WIDTH), locator => (0 => gen_rand_loc_2, others => EMPTY_LOCATOR));
        gen_endpoint_data(endpoint, sub_p.data, PID_MULTICAST_LOCATOR, +1);
        gen_sentinel(sub_p.data);
        gen_rtps_handler_out(sub_p, endpoint, stimulus);
        wr_sig  := (0 => '1', 9 => '1', 10 => '1', 15 => '1', others => '0');
        push_endpoint_reference;
        start_test;
        wait_on_complete;
        stimulus    := EMPTY_TEST_PACKET;
        reference   := EMPTY_TEST_PACKET;
        sub_p.data  := EMPTY_TEST_PACKET;
        p_snp      := p_snp + 1;
        
        TranscriptOpen(RESULTS_FILE, APPEND_MODE);
        SetTranscriptMirror;
        stim_done   <= '1';
        wait until check_done = '1';
        AlertIf((not SB_out.empty) or (not SB_mem.empty), "Incomplete test run");
        ReportAlerts;
        TranscriptClose;
        std.env.stop;
        wait;
    end process;
    
    clock_prc : process
    begin
        clk <= '0';
        wait for 25 ns;
        clk <= '1';
        wait for 25 ns;
    end process;
    
    in_empty_prc : process
    begin
        in_empty        <= '0';
        wait until rd_sig = '1';
        wait until rising_edge(clk);
        in_empty        <= '1';
        wait until rising_edge(clk);
    end process;
    
    endpoint_full_prc : process
    begin
        endpoint_full   <= (others => '0');
        wait until (or endpoint_wr) = '1';
        wait until rising_edge(clk);
        endpoint_full   <= (others => '1');
        wait until rising_edge(clk);
    end process;
    
    alert_prc : process(all)
    begin
        if rising_edge(clk) then
            alertif(in_empty = '1' and rd_sig = '1', "Input FIFO read signal high while empty signal high", ERROR);
            alertif(endpoint_full /= (0 to NUM_ENDPOINTS-1 => '0') and (endpoint_wr /= (0 to NUM_ENDPOINTS-1 => '0')), "Endpoint FIFO write signal high while full signal high", ERROR);
        end if;
    end process;
    
    input_prc : process(all)
    begin
        data_in         <= stimulus.data(cnt_stim);
        last_word_in    <= stimulus.last(cnt_stim);
        
        if rising_edge(clk) then
            if (reset = '1') then
                cnt_stim    <= 0;
                stim_stage  <= IDLE;
                packet_sent <= '1';
            else
                case (stim_stage) is
                    when IDLE =>
                        if (start = '1' and stimulus.length /= 0) then
                            stim_stage  <= BUSY;
                            packet_sent <= '0';
                        end if;
                    when BUSY =>
                        if (rd_sig = '1') then
                            if (cnt_stim = stimulus.length-1) then
                                stim_stage  <= IDLE;
                                packet_sent <= '1';
                                cnt_stim    <= 0;
                            else
                                cnt_stim    <= cnt_stim + 1;
                            end if;
                        end if;
                end case;
            end if;
        end if;
    end process;
    
    output_check_prc : process(all)
    begin
        check_done  <= '0';
        if rising_edge(clk) then
            if (endpoint_wr /= (0 to NUM_ENDPOINTS-1 => '0')) then
                SB_out.Check(endpoint_wr & last_word_out & data_out);
            end if;
            if (stim_done = '1' and SB_out.empty) then
                check_done  <= '1';
            end if;
        end if;
    end process;
    
    mem_check_prc : process
        alias mem is <<signal uut.ram_inst.mem : TEST_RAM_TYPE>>;
        alias mem_op_done is <<signal uut.mem_op_done : std_logic>>;
        variable reference : TEST_PARTICIPANT_MEMORY_FRAME_TYPE;
    begin
        -- SAFEGUARD: (Prevent Fall-through Behavior)
        if (reset /= '0') then
            wait until reset = '0';
        end if;
        -- NOTE: The first read after the packet is sent signifies that the State Machine has begun processing the next packet.
        --       The memory operation that could still be in progress is the last one concerning the last sent packet.
        wait on packet_sent until (packet_sent = '1' and mem_check = '1');
        wait until rising_edge(rd_sig);
        if (mem_op_done /= '1') then
            wait until mem_op_done = '1';
        end if;
        if (not SB_mem.empty) then
            SB_mem.Pop(reference);
            for i in 0 to reference'length-1 loop
                AffirmIf(?? (mem(reference(i).addr) ?= reference(i).data), "Address: " & integer'image(reference(i).addr) & " Received: " & to_hstring(mem(reference(i).addr)) & " Expected: " & to_hstring(reference(i).data));
            end loop;
        end if;
    end process;
    
    watchdog : process
    begin
        wait for 1 ms;
        Alert("Test timeout", FAILURE);
        std.env.stop;
    end process;
    
end architecture;