Skip to content
LibItsGeoNetworking_Functions.ttcn 79.1 KiB
Newer Older
berge's avatar
berge committed
/**
 *  @author     ETSI / STF405 / STF449
berge's avatar
berge committed
 *  @version    $URL$
 *              $Id$
 *  @desc       Module containing functions for GeoNetworking
berge's avatar
berge committed
 *
 */
module LibItsGeoNetworking_Functions {
    
berge's avatar
berge committed
    // Libcommon
    import from LibCommon_BasicTypesAndValues all;
    import from LibCommon_DataStrings all;
    import from LibCommon_VerdictControl {type FncRetCode;}
    import from LibCommon_Sync all;
berge's avatar
berge committed
    import from LibCommon_Time all;
berge's avatar
berge committed
    // LibIts
fischer's avatar
fischer committed
    import from LibItsCommon_Functions all;
reinaortega's avatar
reinaortega committed
    import from LibItsCommon_TestSystem all;
tepelmann's avatar
tepelmann committed
    import from LibItsCommon_TypesAndValues all;
reinaortega's avatar
reinaortega committed
    import from LibItsGeoNetworking_Functions all;
    import from LibItsGeoNetworking_TestSystem all;
berge's avatar
berge committed
    import from LibItsGeoNetworking_TypesAndValues all;
berge's avatar
berge committed
    import from LibItsGeoNetworking_Templates all;
fischer's avatar
fischer committed
    import from LibItsGeoNetworking_Pixits all;
    import from LibItsGeoNetworking_Pics all;
    import from LibItsExternal_TypesAndValues {type MacAddress};
tepelmann's avatar
tepelmann committed
    
tepelmann's avatar
tepelmann committed
    group utFuntions {
tepelmann's avatar
tepelmann committed
        
reinaortega's avatar
reinaortega committed
        /**
         * @desc    Requests to bring the IUT in an initial state
         * @param   p_init The initialisation to trigger.
         */
        function f_utInitializeIut(template (value) UtInitialize p_init) runs on ItsBaseGeoNetworking {
tepelmann's avatar
tepelmann committed
            
reinaortega's avatar
reinaortega committed
            utPort.send(p_init);
            tc_wait.start;
            alt {
                [] utPort.receive(UtResult:true) {
                    tc_wait.stop;
                    log("*** f_utInitializeIut: INFO: IUT initialized ***");
                }
                [] utPort.receive {
                    tc_wait.stop;
                    log("*** f_utInitializeIut: INFO: IUT could not be initialized ***");
                    f_selfOrClientSyncAndVerdict("error", e_error);
                }
                [] tc_wait.timeout {
                    log("*** f_utInitializeIut: INFO: IUT could not be initialized in time ***");
                    f_selfOrClientSyncAndVerdict("error", e_timeout);
                }
                [else] { // Shortcut defaults
tepelmann's avatar
tepelmann committed
                    repeat;
reinaortega's avatar
reinaortega committed
                }
            }
tepelmann's avatar
tepelmann committed
        
tepelmann's avatar
tepelmann committed
         * @desc    Requests to change the position of the IUT
         */
        function f_utChangePosition() runs on ItsBaseGeoNetworking {
        	
        	utPort.send(m_changePosition);
            tc_wait.start;
            alt {
                [] utPort.receive(UtResult:true) {
                    tc_wait.stop;
                    log("*** f_utInitializeIut: INFO: IUT initialized ***");
                }
                [] utPort.receive {
                    tc_wait.stop;
                    log("*** f_utInitializeIut: INFO: IUT could not be initialized ***");
                    f_selfOrClientSyncAndVerdict("error", e_error);
                }
                [] tc_wait.timeout {
                    log("*** f_utInitializeIut: INFO: IUT could not be initialized in time ***");
                    f_selfOrClientSyncAndVerdict("error", e_timeout);
                }
                [else] { // Shortcut defaults
tepelmann's avatar
tepelmann committed
                    repeat;
reinaortega's avatar
reinaortega committed
        }
        
        /**
         * @desc    Triggers event from the application layer
         * @param   p_event The event to trigger.
         */
        function f_utTriggerEvent(template (value) UtGnTrigger p_event) runs on ItsGeoNetworking return boolean {
reinaortega's avatar
reinaortega committed
            
            // Variables
            var boolean v_return := true;

            utPort.send(p_event);
            tc_wait.start;
reinaortega's avatar
reinaortega committed
            alt {
                [] utPort.receive(UtResult:true) {
                    tc_wait.stop;
                }
                [] utPort.receive {
                    tc_wait.stop;
                }
                [] tc_wait.timeout {
                	v_return := false;
reinaortega's avatar
reinaortega committed
                }
                [else] { // Shortcut defaults
tepelmann's avatar
tepelmann committed
                    repeat;
reinaortega's avatar
reinaortega committed
                }
            }
            return v_return;
reinaortega's avatar
reinaortega committed
        }
        
    } // End of group utFunctions
    group geoConfigurationFunctions {
        
        /**
         * @desc This configuration features:
         *       - one ITS node (IUT)
         *       - two ITS nodes (nodeA, nodeB)
         *       - Area1 which only includes NodeB and IUT
tepelmann's avatar
tepelmann committed
         *       - Area2 which only includes NodeB
tepelmann's avatar
tepelmann committed
         *         NodeB being close to the area center
reinaortega's avatar
reinaortega committed
        function f_cf01Up() runs on ItsGeoNetworking {
            // Variables
            var PositionTable v_positionTable := {};
            var GeoAreaTable v_areaTable := {};
            var LongPosVector v_longPosVectorIut, v_longPosVectorNodeA, v_longPosVectorNodeB, v_longPosVectorNodeD;
            map(self:acPort, system:acPort);
            map(self:utPort, system:utPort);
            map(self:geoNetworkingPort, system:geoNetworkingPort);
            // Connect
            f_connect4SelfOrClientSync();
tepelmann's avatar
tepelmann committed
            activate(a_cf01Down());
            //Initialze the IUT
            f_initialState();
            
            //Get positions
            v_longPosVectorIut := f_getIutLongPosVector();
            v_longPosVectorNodeA := f_computePosition(v_longPosVectorIut, c_longitudeFactorNodeA, c_latitudeFactorNodeA);
            v_longPosVectorNodeB := f_computePosition(v_longPosVectorIut, c_longitudeFactorNodeB, c_latitudeFactorNodeB);
            v_longPosVectorNodeD := f_computePosition(v_longPosVectorIut, c_longitudeFactorNodeD, c_latitudeFactorNodeD);
            // Propagate GN addresses
            v_longPosVectorNodeA.gnAddr := f_getTsGnLocalAddress(c_compNodeA);
            v_longPosVectorNodeB.gnAddr := f_getTsGnLocalAddress(c_compNodeB);
tepelmann's avatar
tepelmann committed
            // Position table
            f_addPosition(v_positionTable, c_compIut, v_longPosVectorIut);
            f_addPosition(v_positionTable, c_compNodeA, v_longPosVectorNodeA);
            f_addPosition(v_positionTable, c_compNodeB, v_longPosVectorNodeB);
berge's avatar
berge committed
            f_addPosition(v_positionTable, c_compNodeD, v_longPosVectorNodeD);
            // Area table
tepelmann's avatar
tepelmann committed
            f_addArea(v_areaTable, c_area1,
berge's avatar
berge committed
                f_computeCircularArea(v_longPosVectorNodeD, float2int(1.1 * f_distance(v_longPosVectorNodeB, v_longPosVectorNodeD))));
tepelmann's avatar
tepelmann committed
            f_addArea(v_areaTable, c_area2,
berge's avatar
berge committed
                f_computeCircularArea(v_longPosVectorNodeB, float2int(1.1 * f_distance(v_longPosVectorNodeB, v_longPosVectorNodeD))));
            f_initialiseComponent(v_positionTable, v_areaTable, c_compNodeB);
        } // end f_cf01Up
berge's avatar
berge committed
        /**
         * @desc Deletes configuration cf01
reinaortega's avatar
reinaortega committed
        function f_cf01Down() runs on ItsGeoNetworking {
            unmap(self:acPort, system:acPort);
            unmap(self:utPort, system:utPort);
            unmap(self:geoNetworkingPort, system:geoNetworkingPort);
            
            // Disconnect
            f_disconnect4SelfOrClientSync();
            
        } // end f_cf01Down
        
        /**
         * @desc This configuration features:
         *       - one ITS node (IUT)
         *       - one ITS node (NodeB)
berge's avatar
berge committed
         *       - one ITS node (NodeD)
         *       - Area1 which only includes NodeB, NodeD and IUT
tepelmann's avatar
tepelmann committed
         *       - Area2 which only includes NodeB and NodeD
         *         NodeB being close to the area center
         *
         * @param p_nodeB   Component for NodeB
         * @param p_nodeD   Component for NodeD
reinaortega's avatar
reinaortega committed
        function f_cf02Up(out ItsGeoNetworking p_nodeB, out ItsGeoNetworking p_nodeD) runs on ItsMtc {
            
            // Variables
Loading full blame...