Skip to content
ItsRSUsSimulator_TestCases.ttcn 10.8 KiB
Newer Older
garciay's avatar
garciay committed
module ItsRSUsSimulator_TestCases {
    
    // Libcommon
    import from LibCommon_VerdictControl all;
    import from LibCommon_Sync all;
    
garciay's avatar
garciay committed
    // LibIts
    import from ITS_Container language "ASN.1:1997" all;
    import from CAM_PDU_Descriptions language "ASN.1:1997" all;
    
garciay's avatar
garciay committed
    // LibItsCommon
    import from LibItsCommon_Functions all;
    
    // LibItsGeoNetworking
    import from LibItsGeoNetworking_TestSystem all;
    import from LibItsGeoNetworking_TypesAndValues all;
    import from LibItsGeoNetworking_Templates all;
garciay's avatar
garciay committed
    import from LibItsGeoNetworking_Functions {
        function
            f_distance
    };
garciay's avatar
garciay committed
    
    // LibItsDenm
    import from LibItsDenm_Templates all;
    
    // AtsRSUsSimulator
    import from ItsRSUsSimulator_TypesAndValues all;
    import from ItsRSUsSimulator_Templates all;
    import from ItsRSUsSimulator_TestSystem all;
    import from ItsRSUsSimulator_Functions all;
garciay's avatar
garciay committed
    import from ItsRSUsSimulator_Pics all;
garciay's avatar
garciay committed
    import from ItsRSUsSimulator_Pixits all;
    
    testcase TC_RSUSIMU_BV_01() runs on ItsRSUsSimulator system ItsRSUsSimulatorSystem {
garciay's avatar
garciay committed
        // Local variables
        var template (value) Payload v_payload;
        var GeoNetworkingInd v_gnInd;
        var CfEvent v_cfEvent;
garciay's avatar
garciay committed
        
        // Test control
        
        // Test component configuration
        f_cf01Up();
            
        // Test adapter configuration
        
        // Preamble
        f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
        
        // Test Body
        if (ispresent(vc_rsuMessagesValueList[vc_rsu_id].beacon)) {
            tc_beacon.start;
        }
        if (ispresent(vc_rsuMessagesValueList[vc_rsu_id].cam)) {
            tc_cam.start;
        }
        if (ispresent(vc_rsuMessagesValueList[vc_rsu_id].denms)) {
            tc_denm.start;
        }
        if (ispresent(vc_rsuMessagesValueList[vc_rsu_id].mapem)) {
garciay's avatar
garciay committed
            tc_mapem.start;
        }
        if (ispresent(vc_rsuMessagesValueList[vc_rsu_id].spatems)) {
garciay's avatar
garciay committed
            tc_spatem.start;
        }
        if (ispresent(vc_rsuMessagesValueList[vc_rsu_id].ivim)) {
garciay's avatar
garciay committed
            tc_ivim.start;
        }
garciay's avatar
garciay committed
        alt {
            [] geoNetworkingPort.receive(
                mw_geoNwInd(
                    mw_geoNwPdu(
                        mw_geoNwTsbPacketWithNextHeader_srem(
garciay's avatar
garciay committed
                            ?,
                            ?,
                            e_btpB
            )))) -> value v_gnInd { // Receive a SREM message
                log("*** " & testcasename() & ": DEBUG: Processing SREM ***");
garciay's avatar
garciay committed
                f_processSrem(v_gnInd.msgIn);
                repeat;
            }
garciay's avatar
garciay committed
            /*[] geoNetworkingPort.receive(
                mw_geoNwInd(
                    mw_geoNwPdu(
                        mw_geoNwTsbPacketWithNextHeader_denm(
                            ?,
                            ?,
                            e_btpB // TODO Refined to exclude RSU StationID
            )))) -> value v_gnInd { // Receive a DENM message
                log("*** " & testcasename() & ": DEBUG: Processing DENM ***");
                // Nothing to do, just for logging purposes
                repeat;
garciay's avatar
garciay committed
            }*/
garciay's avatar
garciay committed
            [] geoNetworkingPort.receive(mw_geoNwInd(?)) -> value v_gnInd { // Receive a message
                log("*** " & testcasename() & ": DEBUG: Recieving unsollicited message ***");
garciay's avatar
garciay committed
                // Nothing to do, just for logging purposes
                repeat;
            }
            [] cfPort.receive(CfEvent:?) -> value v_cfEvent {
                log("*** " & testcasename() & ": DEBUG: Configuration port command:", v_cfEvent, " ***");
                if (f_process_cf_event(v_cfEvent) == true) {
                    repeat;
                }
            }
            [vc_beacon == true] tc_beacon.timeout {
                log("*** " & testcasename() & ": DEBUG: Processing BEACON ***");
                f_prepare_beacon(v_payload);
                f_send(v_payload, PICS_CAM_ITS_AID);
                tc_beacon.start;
                repeat;
            }
            [vc_cam == true] tc_cam.timeout {
                log("*** " & testcasename() & ": DEBUG: Processing CAM ***");
garciay's avatar
garciay committed
                f_prepare_cam(v_payload);
                f_send(v_payload, PICS_CAM_ITS_AID);
garciay's avatar
garciay committed
                tc_cam.start;
                repeat;
            }
            [vc_denm == true] tc_denm.timeout {
                log("*** " & testcasename() & ": DEBUG: Processing DENM ***");
                for (var integer v_i := 0; v_i < lengthof(vc_rsuMessagesValueList[vc_rsu_id].denms); v_i := v_i + 1) {
                    f_prepare_denm(v_payload);
                    f_send(v_payload, PICS_DENM_ITS_AID);
                } // End of 'for' 
                tc_denm.start;
garciay's avatar
garciay committed
                repeat;
            }
            [vc_mapem == true] tc_mapem.timeout {
garciay's avatar
garciay committed
                log("*** " & testcasename() & ": DEBUG: Processing MAPEM ***");
                f_prepare_mapem(v_payload);
                f_send(v_payload, PICS_MAPEM_ITS_AID);
garciay's avatar
garciay committed
                tc_mapem.start;
                repeat;
            }
            [vc_spatem == true] tc_spatem.timeout {
garciay's avatar
garciay committed
                log("*** " & testcasename() & ": DEBUG: Processing SPATEM ***");
                for (var integer v_counter := 0; v_counter < lengthof(vc_rsuMessagesValueList[PX_RSU_ID - 1].spatems); v_counter := v_counter + 1) {
                    f_prepare_spatem(vc_rsuMessagesValueList[PX_RSU_ID - 1].spatems[v_counter], v_payload);
                    f_send(v_payload, PICS_SPATEM_ITS_AID);
garciay's avatar
garciay committed
                tc_spatem.start;
                repeat;
            }
            [vc_ivim == true] tc_ivim.timeout {
garciay's avatar
garciay committed
                log("*** " & testcasename() & ": DEBUG: Processing IVIM ***");
                f_prepare_ivim(v_payload);
                f_send(v_payload, PICS_IVIM_ITS_AID);
garciay's avatar
garciay committed
                tc_ivim.start;
                repeat;
            }
garciay's avatar
garciay committed
        } // End of 'alt' statement
        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
        
        // Postamble
        f_cf01Down();
        
garciay's avatar
garciay committed
    } // End of TC_RSUSIMU_BV_01
    
    /**
     * @remark: All PICS_GENERATE_xxx = false
     *          PICS_CAM_FREQUENCY = 0.1
     */
    testcase TC_RSUSIMU_BV_02() runs on ItsRSUsSimulator system ItsRSUsSimulatorSystem {
        // Local variables
        var VehiclesSimulator v_vehicles := {};
        var integer v_vehiclesIdx := 0;
        var charstring v_stationIDs := "";
        var charstring v_stationID;
        var GeoNetworkingInd v_gnInd;
        var CfEvent v_cfEvent;
        
        // Test control
        
        // Test component configuration
        f_cf01Up();
            
        // Test adapter configuration
        
        // Preamble
        f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
        
        // Test Body
        tc_ac.start;
        alt {
            [] geoNetworkingPort.receive(
                mw_geoNwInd(
                    mw_geoNwPdu(
                        mw_geoNwShbPacketWithNextHeader_cam(
                            mw_longPosVectorPosition_vendors(
                                PICS_UC6_VEHICLE_POSITION            // Ignore RSUsimultor CAM messages
garciay's avatar
garciay committed
                            ),
                            ?,
                            e_btpB
            )))) -> value v_gnInd { // Receive a DENM message
                tc_ac.stop;
                // Check if already processed
                v_stationID := int2str(v_gnInd.msgIn.gnPacket.packet.payload.decodedPayload.btpPacket.payload.decodedPayload.camPacket.header.stationID);
                if (regexp(v_stationID, charstring:"([1-9]#(1,6)),", 0) == "") { // Non simulated vehicle
                    // Compute point intersection
                    if (LibItsGeoNetworking_Functions.f_distance(
                        v_gnInd.msgIn.gnPacket.packet.extendedHeader.shbHeader.srcPosVector,
                        PICS_UC6_DETECTION_POINT
                        ) <= PICS_UC6_DETECTION_EPSILLON
                    ) {
                        v_vehicles[v_vehiclesIdx] := ItsRSUsSimulator.create("Node" & int2char(v_vehiclesIdx + 65)) alive;
                        v_vehicles[v_vehiclesIdx].start(f_startVehicleSimulator(v_vehicles[v_vehiclesIdx], v_vehiclesIdx));
                        v_vehiclesIdx := v_vehiclesIdx + 1;
                        v_stationIDs := v_stationIDs & v_stationID & ",";
                    }
                } else {
                    // Nothing to do
                }
                tc_ac.start;
                repeat;
            }
            [] geoNetworkingPort.receive { // Receive a message
                log("*** " & testcasename() & ": DEBUG: Recieving unsollicited message ***");
                // Nothing to do, just for logging purposes
                tc_ac.stop;
                tc_ac.start;
                repeat;
            }
            [] cfPort.receive(CfEvent:?) -> value v_cfEvent {
                log("*** " & testcasename() & ": DEBUG: Configuration port command:", v_cfEvent, " ***");
                if (f_process_cf_event(v_cfEvent) == true) {
                    repeat;
                }
                all component.stop;
            }
            [] tc_ac.timeout {
                log("*** " & testcasename() & ": DEBUG: No CAM message received ***");
                all component.stop;
            }
        } // End of 'alt' statement
        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
        
        // Postamble
        for (var integer v_idx := 0; v_idx < lengthof(v_vehicles); v_idx := v_idx + 1) {
            v_vehicles[v_idx].done;
        } // End of 'for' statement
        f_cf01Down();
        
    } // End of TC_RSUSIMU_BV_02
    
    group tc_RSUSIMU_BV_02 {
        
        function f_startVehicleSimulator(
                                         in ItsRSUsSimulator p_component,
                                         in integer p_idx
        ) runs on ItsRSUsSimulator {
            
            // Local variables
            var integer v_idx := 0;
            var template (value) CAM v_cam;
            
            f_initialiseVehicleSimulatorComponent(p_component, v_cam);
            
            tc_ca_uc6.start;
garciay's avatar
garciay committed
            alt {
                [] tc_cam.timeout {
                    log("*** " & testcasename() & ": DEBUG: Processing CAM ***");
                    f_send_vehicle_cam(v_cam, v_idx);
                    v_idx := v_idx + 1;
                    if (v_idx < lengthof(PICS_USECASE6_VEHICLE_POSITIONS)) {
                        tc_ca_uc6.start;
garciay's avatar
garciay committed
                        repeat;
                    } // else, terminate
                }
            } // End of 'altstep' statement
            
            f_uninitialiseVehicleSimulatorComponent(p_component);
            
        } // End of f_startVehicleSimulator
        
    } // End of group tc_RSUSIMU_BV_02 
garciay's avatar
garciay committed
    
} // End of module ItsRSUsSimulator_TestCases