LibItsGeoNetworking_Functions.ttcn 15.2 KB
Newer Older
berge's avatar
berge committed
/**
 *	@author 	ETSI / STF405
 *  @version 	$URL$
 *				$Id$
 *	@desc		Module containing functions for GeoNetworking
 *
 */
module LibItsGeoNetworking_Functions {
    
berge's avatar
berge committed
    // Libcommon
    import from LibCommon_BasicTypesAndValues all;
    import from LibCommon_VerdictControl {type FncRetCode;}
berge's avatar
berge committed
    // LibIts
    import from LibIts_TestSystem all;
    import from LibIts_Interface all; 
berge's avatar
berge committed
    import from LibItsGeoNetworking_TypesAndValues all;
berge's avatar
berge committed
    import from LibItsGeoNetworking_Templates all;
berge's avatar
berge committed
    /**
     * @desc 	Create Facility component and connects GeoNetworking port
berge's avatar
berge committed
     * @remark	Only used when ItsFa is a PTC
berge's avatar
berge committed
     * @param	p_ptcDenm returned Facility component variable
     */    
berge's avatar
berge committed
    function f_ptcGeoNetworkingUp(out ItsNt p_ptcGeoNetworking) {
berge's avatar
berge committed
        
        // Create Facility component
        p_ptcGeoNetworking := ItsNt.create("GeoNetworking Tester");
berge's avatar
berge committed
        
        // map ports
        map(p_ptcGeoNetworking:geoNetworkingPort, system:geoNetworkingPort);
        
berge's avatar
berge committed
    } // end f_ptcGeoNetworkingUp       
berge's avatar
berge committed
    
    /**
     * @desc 	Wait for component to finish and unmap GeoNetworking ports
berge's avatar
berge committed
     * @remark	Only used when ItsFa is a PTC
berge's avatar
berge committed
     * @param	p_camPtc Facility component variable
     */    
berge's avatar
berge committed
    function f_ptcGeoNetworkingDown(in ItsNt p_ptcGeoNetworking) runs on ItsMtc {    
berge's avatar
berge committed
    	tc_guard.start;
        alt {
        	[] p_ptcGeoNetworking.done {
            	tc_guard.stop;
            }
            
            [] tc_guard.timeout {
berge's avatar
berge committed
             	log("*** f_ptcGeoNetworkingDown: ERROR: Timeout while waiting for component ***");
berge's avatar
berge committed
             	setverdict(inconc);   
            }
        }
        unmap(p_ptcGeoNetworking:geoNetworkingPort);
        
berge's avatar
berge committed
    } // end f_ptcGeoNetworkingDown
berge's avatar
berge committed
    
berge's avatar
berge committed
    group geoAltsteps {
berge's avatar
berge committed
       	/**
         * @desc The base default.
         */
        altstep a_default() runs on ItsNt {
            [] geoNetworkingPort.receive {
                setverdict (inconc, "Received an unexpected message");
                //TODO shall stop be called here?
                stop;
            }
            [] tc_wait.timeout {
                setverdict (inconc, "Timeout while awaiting reaction of the IUT prior to Upper Tester action");
                //TODO shall stop be called here?
                stop;
            }
            [] tc_ac.timeout {
                setverdict (inconc, "Timeout while awaiting the reception of a message");
                //TODO shall stop be called here?
                stop;
            }
        }        
berge's avatar
berge committed
        
        group geoGeoUnicastAltsteps {
            
            /**
             * @desc Receive GeoUnicast packet
             */
        	altstep a_receiveGeoUnicast(
        	   	in template (present) LongPosVector p_senderLongPosVec,
    	    	in template (present) ShortPosVector p_destinationShortPosVec,
berge's avatar
berge committed
    			in template (present) StationTypeIdentifier p_stationType,
    	    	in template (present) UInt16 p_seqNumber
        	) runs on ItsNt {
        	    
        	    [] geoNetworkingPort.receive(mw_geoNwInd(mw_geoNwPdu(mw_geoUnicastHeader(
        	    	p_senderLongPosVec,
berge's avatar
berge committed
    				p_stationType,
berge's avatar
berge committed
        	}     
        	
        	/**
             * @desc Receive GeoUnicast packet for specific destination
             */
        	altstep a_receiveGeoUnicastWithDestination(in template (present) ShortPosVector p_destinationShortPosVec) runs on ItsNt {
        	    [] a_receiveGeoUnicast(?, p_destinationShortPosVec, ?, ?) {}
berge's avatar
berge committed
        	}     
            
            /**
             * @desc Receive any GeoUnicast packet
             */
        	altstep a_receiveAnyGeoUnicast() runs on ItsNt {
        	    
        	    [] a_receiveGeoUnicast(?, ?, ?, ?) {}
        	}  
            
        } // end geoGeoUnicastAltsteps
        
        group geoLocationServiceAltsteps {

            /**
             * @desc Receive Location Service Request
             */
            altstep a_receiveLsRequest(
                in template (present) StationTypeIdentifier p_stationType,
                in template (present) UInt16 p_seqNumber,
                in template (present) GN_Address p_gnAddress,
                out template (value) LongPosVector p_reqSrcPosVector
berge's avatar
berge committed
            ) runs on ItsNt {
                var GeoNetworkingInd v_msg;
                
                [] geoNetworkingPort.receive(
                    mw_geoNwInd(
                        mw_geoNwPdu(
                            mw_lsRequestHeader(
                                p_stationType,
                                p_seqNumber,
                                p_gnAddress
                            )
                        )
                    )
                ) -> value v_msg {
                    p_reqSrcPosVector := v_msg.msgIn.header.lsRequestHeader.srcPosVector;
                }
berge's avatar
berge committed
            }
            
            /**
             * @desc Receive any Location Service Request
             */
            altstep a_receiveAnyLsRequest() runs on ItsNt {
                var LongPosVector v_reqSrcPosVector;
                
                [] a_receiveLsRequest(?, ?, ?, v_reqSrcPosVector) {}
berge's avatar
berge committed
            }
            
            /**
             * @desc Receive Location Service Request and send Location Service Reply  
             */
            altstep a_receiveLsRequestAndReply(
            	in template (present) StationTypeIdentifier p_reqStationType,
    			in template (present) UInt16 p_reqSeqNumber,
            	in template (value) GN_Address p_gnAddress,
            	in template (value)	LongPosVector p_repSrcPosVector,
            	in template (value)	LongPosVector p_repSenderPosVector,
            	in template (value) StationTypeIdentifier p_repStationType
berge's avatar
berge committed
            ) runs on ItsNt {
                var LongPosVector v_repDstPosVector;
                [] a_receiveLsRequest(p_reqStationType, p_reqSeqNumber, p_gnAddress, v_repDstPosVector) {
                    f_sendGeoNetMessage(m_geoNwReq(m_geoNwPdu(
                    	m_lsReplyHeader(
                      p_repSrcPosVector,
                    	v_repDstPosVector,
berge's avatar
berge committed
                    	p_repSenderPosVector,
            			p_repStationType,
berge's avatar
berge committed
                }
            }
          
        } // end geoLocationServiceAltsteps
        
        
    } // end geoAltsteps
    
    group preambles {
        
        /**
         * @desc The default preamble.
         */
        function f_prDefault() runs on ItsNt {
            activate(a_default());
        }
        
        /**
         * @desc Brings the IUT into an initial state.
         * @return 
         */
        function f_prInitialState() runs on ItsNt {
            
            f_prDefault();
            
            // TODO: any specific action ?
            
            setverdict(pass);
        }
        
        function f_handleLocationService(
          in template (present) StationTypeIdentifier p_reqStationType,
          in template (present) UInt16 p_reqSeqNumber,
          in template (value) GN_Address p_gnAddress,
          in template (value) LongPosVector p_repSrcPosVector,
          in template (value) LongPosVector p_repSenderPosVector,
          in template (value) StationTypeIdentifier p_repStationType
        ) runs on ItsNt {
            
            tc_ac.start;
            alt {
                [] a_receiveLsRequestAndReply(p_reqStationType, p_reqSeqNumber, p_gnAddress, 
                p_repSrcPosVector, p_repSenderPosVector, p_repStationType) {
                    tc_ac.stop;
                }
            }
            
        }
        
        function f_processLocationService(
          in template (value) LongPosVector p_reqSrcPosVector,
          in template (value) StationTypeIdentifier p_reqStationType,
          in template (value) UInt16 p_reqSeqNumber,
          in template (value) GN_Address p_gnAddress,
          out template (value) LongPosVector p_repSrcPosVector
        ) runs on ItsNt return FncRetCode {
            var FncRetCode v_ret := e_error;
            var GeoNetworkingInd v_msg;
            
            f_sendGeoNetMessage(
                m_geoNwReq(
                    m_geoNwPdu(
                        m_lsRequestHeader(
                            p_reqSrcPosVector,
                            p_reqSrcPosVector,
                            p_reqStationType,
                            p_reqSeqNumber,
                            p_gnAddress
                        )
                    )
                )
            );
            
            tc_ac.start;
            alt {
                [] geoNetworkingPort.receive(
                        mw_geoNwInd(
                            mw_geoNwPdu(
                                mw_lsReplyHeader(
                                    p_reqStationType, 
                                    p_reqSeqNumber,
                                    ?,
                                    p_reqSrcPosVector
                                )
                            )
                        )
                    ) -> value v_msg { 
                    tc_ac.stop;
                    p_repSrcPosVector := v_msg.msgIn.header.lsRequestHeader.srcPosVector;
                    v_ret := e_success;
                }
            }
            
            return v_ret;
        }
        
    } // end preambles
    
    group postambles {
        
        /**
         * @desc The default postamble.
         */
        function f_poDefault() runs on ItsNt {
            setverdict(pass);           
        }
    } // end postambles
    
    group upperTester {
        
        function f_utGenerateIpv6Message() runs on ItsNt {
            
        }
        
    } // end upperTester
    
berge's avatar
berge committed
    group testAdapter {
        
        function f_taStartBeaconing(in template (value) Header p_beaconHeader) {
            
berge's avatar
berge committed
        }
        
        function f_taStopBeaconing() {
            
berge's avatar
berge committed
        }
berge's avatar
berge committed
    } // end testAdapter
    
    group commonFunctions {
        
        /**
         * @desc Gets the value of the lifetime in seconds.
         * @return 
         */
        function f_getLifetimeValue(in Lifetime p_lifetime) runs on ItsNt return float {
            var float v_lifetime := 0.0;
          
            select (p_lifetime.ltBase) {
                case (e_50ms) {
                    v_lifetime := int2float(p_lifetime.multiplier) * 0.5;
                }
                case (e_1s) {
                    v_lifetime := int2float(p_lifetime.multiplier) * 1.0;
                }
                case (e_10s) {
                    v_lifetime := int2float(p_lifetime.multiplier) * 10.0;
                }
                case (e_100s) {
                    v_lifetime := int2float(p_lifetime.multiplier) * 100.0;
                }
            }
          
            return v_lifetime;
        }
      
    } // end commonFunctions
    
berge's avatar
berge committed
    group testerFunctions {
     	
      function f_sendGeoNetMessage(in GeoNetworkingReq p_geoNetReq) runs on ItsNt {
          geoNetworkingPort.send(p_geoNetReq);
          if (not (ischosen(p_geoNetReq.msgOut.header.shbHeader) or ischosen(p_geoNetReq.msgOut.header.beaconHeader))) {
              f_setLocalSequenceNumber();
          }
      }
      
berge's avatar
berge committed
     	function f_getTesterLongPosVector() return LongPosVector {
berge's avatar
berge committed
            var LongPosVector v_longPosVector;
            
berge's avatar
berge committed
            return v_longPosVector; 
        }
        
berge's avatar
berge committed
     	function f_getTesterGnAddress() return GN_Address {
     	 	var GN_Address v_gnAddress;
berge's avatar
berge committed
     	 	
			return v_gnAddress;
     	}
      
        /**
         * @desc Sets the value of the sequence number for the next event.
         * @return 
         */
        function f_setLocalSequenceNumber() runs on ItsNt {
            vc_localSeqNumber := (vc_localSeqNumber + 1) mod c_uInt16Max; //TODO check if c_uInt16Max should be replaced by module parameter
        }
        
    } // end testerFunctions
    
    group iutFunctions {
        
        function f_getIutGnAddress() return GN_Address {
            var GN_Address v_gnAddress;
              
            //TODO
          
            return v_gnAddress;
        }
        
        /**
         * @desc Gets the LS retransmission timer.
         * @return 
         */
        function f_getLSRetransmitTimer() return float {
            var float v_itsGnLocationServiceRetransmitTimer := 1.0;
            
            //TODO get the value from PIXIT or MIB
            
            return v_itsGnLocationServiceRetransmitTimer;
        }
        
        /**
         * @desc Gets the LS maximum retransmission number.
         * @return 
         */
        function f_getLSMaxRetrans() return integer {
            var integer v_itsGnLocationServiceMaxRetrans := 10;
            
            //TODO get the value from PIXIT or MIB
            
            return v_itsGnLocationServiceMaxRetrans;
        }
        
        /**
         * @desc Gets the upper limit of the maximum lifetime.
         * @return 
         */
        function f_getMaxPacketLifeTime() return float {
            var float v_itsGnMaxPacketLifetime := 600.0;
            
            //TODO get the value from PIXIT or MIB
            
            return v_itsGnMaxPacketLifetime;
        }
        
        /**
         * @desc Gets delta for timers.
         * @return 
         */
        function f_getDeltaTimer() return float {
            var float v_deltaTimer := 0.1;
            
            //TODO get the value from PIXIT
            
            return v_deltaTimer;
        }
        
    } // end iutFunctions
    
    group neighborFunctions {
      
      function f_getNeighborLongPosVector() return LongPosVector {
            var LongPosVector v_longPosVector;
            
            //TODO
            
            return v_longPosVector; 
        }
berge's avatar
berge committed
        
    } // end testerFunctions
    
    group posVectorFunctions {
        
berge's avatar
berge committed
        function f_longPosVector2ShortPosVector(in LongPosVector p_longPosVector) return ShortPosVector {
            var ShortPosVector v_shortPosVector;
            
            v_shortPosVector := {
                gnAddr := p_longPosVector.gnAddr, 
                timestamp := p_longPosVector.timestamp, 
                latitute := p_longPosVector.latitute, 
                longitude := p_longPosVector.longitude
            };
            
berge's avatar
berge committed
            return v_shortPosVector; 
        }
        
berge's avatar
berge committed
        function f_getIutShortPosVector() return ShortPosVector {
            var ShortPosVector v_shortPosVector;
            
berge's avatar
berge committed
            return v_shortPosVector; 
        }
        
berge's avatar
berge committed
    } // end posVectorFunctions
    
berge's avatar
berge committed
} // end LibItsGeoNetworking_Functions