ItsRSUsSimulator_Functions.ttcn 11.6 KB
Newer Older
garciay's avatar
garciay committed
1
2
3
4
5
6
7
8
9
10
11
12
13
module ItsRSUsSimulator_Functions {
    
    // LibCommon
    import from LibCommon_BasicTypesAndValues all;
    import from LibCommon_DataStrings all;
    import from LibCommon_VerdictControl all;
    import from LibCommon_Sync all;
    import from LibCommon_Time all;
    
    // LibIts
    import from ITS_Container language "ASN.1:1997" all;
    import from CAM_PDU_Descriptions language "ASN.1:1997" all;
    import from DENM_PDU_Descriptions language "ASN.1:1997" all;
14
15
16
17
18
    import from MAPEM_PDU_Descriptions language "ASN.1:1997" all;
    import from SPATEM_PDU_Descriptions language "ASN.1:1997" all;
    import from IVIM_PDU_Descriptions language "ASN.1:1997" all;
    import from SREM_PDU_Descriptions language "ASN.1:1997" all;
    import from SSEM_PDU_Descriptions language "ASN.1:1997" all;
garciay's avatar
garciay committed
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
    
    // LibItsCommon
    import from LibItsCommon_Functions all;
    
    // LibItsBtp
    import from LibItsBtp_TypesAndValues all;
    import from LibItsBtp_Templates all;
    
    // LibItsDenm
    import from LibItsDenm_Templates all;
    
    // LibItsGeoNetworking
    import from LibItsGeoNetworking_TestSystem all;
    import from LibItsGeoNetworking_Functions all;
    import from LibItsGeoNetworking_Templates all;
    import from LibItsGeoNetworking_TypesAndValues all;
    import from LibItsGeoNetworking_Pixits all;
    
    // AtsRSUsSimulator
    import from ItsRSUsSimulator_TypesAndValues all;
    import from ItsRSUsSimulator_TestSystem all;
    import from ItsRSUsSimulator_Templates all;
    import from ItsRSUsSimulator_Pics all;
    import from ItsRSUsSimulator_Pixits all;
    
    group geoConfigurationFunctions {
        
        /**
         * @desc This configuration features:
         *       - one ITS node (IUT)
         *       - two ITS nodes (nodeA, nodeB)
         *       - Area1 which only includes NodeB and IUT
         *       - Area2 which only includes NodeB
         *         NodeB being close to the area center
         */
        function f_cf01Up() runs on ItsRSUsSimulator {
            
            // Local variables
            var template (value) DenmParmContainers v_denmParmContainers;
garciay's avatar
garciay committed
58
59
            var template (omit) DENMs v_denms := omit;
            var template (omit) CAM v_cam := omit;
60
61
62
63
            var template (omit) MAPEM v_mapem := omit;
            var template (omit) SPATEMs v_spatems := omit;
            var template (omit) IVIM v_ivim := omit;
            var template (omit) SSEM v_ssem := omit;
garciay's avatar
garciay committed
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
            var integer v_counter;
            
            // Map
            map(self:acPort, system:acPort);
            map(self:utPort, system:utPort);
            map(self:geoNetworkingPort, system:geoNetworkingPort);
            
            // Connect
            f_connect4SelfOrClientSync();
            activate(a_cf01Down());
            
            // Initialise secured mode
            f_initialiseSecuredMode();
            
            //Initialze the IUT
garciay's avatar
garciay committed
79
//            f_initialState();
garciay's avatar
garciay committed
80
81
82
83
84
            
            // Initialisations
            vc_longPosVectorRsu := PICS_RSU_PARAMS[PX_RSU_ID - 1].longPosVector;
            // TODO MAPEM
            // TODO IVIM
garciay's avatar
garciay committed
85
86
87
            if (PICS_GENERATE_DENM) {
                // Build the list of the DENM events
                for (v_counter := 0; v_counter < lengthof(PICS_DENM_EVENTS_RSU[PX_RSU_ID - 1]); v_counter := v_counter + 1) {
88
                    // Build DENM with dynamic values
garciay's avatar
garciay committed
89
90
91
                    v_denmParmContainers := m_denmParmContainers(
                        PICS_RSU_PARAMS[PX_RSU_ID - 1].stationID,
                        f_getDenmSequenceNumber(),
92
                        PICS_DENM_REPETITION_INTERVAL,
garciay's avatar
garciay committed
93
94
95
96
97
98
99
100
101
102
103
                        PICS_DENM_EVENTS_RSU[PX_RSU_ID - 1][v_counter].eventPosition,
                        PICS_DENM_EVENTS_RSU[PX_RSU_ID - 1][v_counter].causeCodeType,
                        PICS_DENM_EVENTS_RSU[PX_RSU_ID - 1][v_counter].eventHistory
                    );
                    v_denms[v_counter] := valueof(
                            m_denmPdu(
                                m_denm(
                                       v_denmParmContainers.managementContainer, 
                                       v_denmParmContainers.situationContainer,
                                       v_denmParmContainers.locationContainer
                        )));
104
105
106
                    if (ispresent(PICS_DENM_EVENTS_RSU[PX_RSU_ID - 1][v_counter].roadWorksContainerExtended)) {
                        v_denms[v_counter].denm.alacarte := m_alacarte(PICS_DENM_EVENTS_RSU[PX_RSU_ID - 1][v_counter].roadWorksContainerExtended);
                    }
garciay's avatar
garciay committed
107
108
109
110
111
112
113
114
115
116
117
118
119
                } // End of 'for' loop
            }
            if (PICS_GENERATE_CAM) {
                // Build the list of the CAM events
                v_cam := valueof(
                    m_camParm(
                        PICS_RSU_PARAMS[PX_RSU_ID - 1].stationID,
                        m_rsuPosition(
                            vc_longPosVectorRsu.latitude,
                            vc_longPosVectorRsu.longitude
                        ), 
                        PICS_RSU_PARAMS[PX_RSU_ID - 1].pathHistory
                    )
garciay's avatar
garciay committed
120
                );
garciay's avatar
garciay committed
121
            } 
garciay's avatar
garciay committed
122
            // Build the messages value list for this RSU
123
            vc_rsuMessagesValueList[PX_RSU_ID - 1] := 
garciay's avatar
garciay committed
124
                m_rsuProfile(
garciay's avatar
garciay committed
125
                    v_cam, 
126
                    v_denms,
garciay's avatar
garciay committed
127
                    v_mapem,
128
129
130
131
                    v_spatems,
                    v_ivim,
                    v_ssem
            );
garciay's avatar
garciay committed
132
133
134
135
136
137
138
139
140
141
142
143
            if (PICS_RSU_PARAMS[PX_RSU_ID - 1].geoShape == e_geoCircle) {
                vc_geoArea := f_computeCircularArea(vc_longPosVectorRsu, PICS_RSU_PARAMS[PX_RSU_ID - 1].geoParms.radius);
            } else {
                log("*** " & testcasename() & ": INCONC: Wrong PICS_RSU_GEOAREA_FORM event initialisation ***");
                setverdict(inconc);
                stop;
            }
            
        } // End of function f_cf01Up
        
        function f_cf01Down() runs on ItsRSUsSimulator {
            
144
145
            vc_rsuMessagesValueList := {};
            
garciay's avatar
garciay committed
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
            f_uninitialiseSecuredMode();
            
            // Unmap
            unmap(self:acPort, system:acPort);
            unmap(self:utPort, system:utPort);
            unmap(self:geoNetworkingPort, system:geoNetworkingPort);
            
            // Disconnect
            f_disconnect4SelfOrClientSync();
            
        } // End of function f_cf01Down
        
    } // End of group geoConfigurationFunctions
    
    function f_prepare_cam(
                           out template (value) Payload p_payload
    ) runs on ItsRSUsSimulator {
        
        vc_rsuMessagesValueList[PX_RSU_ID - 1].cam.cam.generationDeltaTime := f_getCurrentTime() mod 65536; // See ETSI EN 302 637-2 V1.3.0 - Clause B.3 generationDelatTime
        p_payload := valueof(
            f_adaptPayload(
                bit2oct(
                    encvalue(
                        valueof(
                            vc_rsuMessagesValueList[PX_RSU_ID - 1].cam
                ))),
                PICS_CAM_BTP_DESTINATION_PORT,
                PICS_CAM_BTP_SOURCE_PORT
            )
        );
    }
    
    function f_prepare_denm(
                            out template (value) Payload p_payload
    ) runs on ItsRSUsSimulator {
        
        vc_rsuMessagesValueList[PX_RSU_ID - 1].denms[vc_denmEventCounter].denm.management.referenceTime  := f_getCurrentTime();
        p_payload := valueof(
            f_adaptPayload(
                bit2oct(
                    encvalue(
                        valueof(vc_rsuMessagesValueList[PX_RSU_ID - 1].denms[vc_denmEventCounter]
                ))),
                PICS_DENM_BTP_DESTINATION_PORT,
                PICS_DENM_BTP_SOURCE_PORT
            )
        ); 
        vc_denmEventCounter := (vc_denmEventCounter + 1) mod lengthof(vc_rsuMessagesValueList[PX_RSU_ID - 1].denms);
    }
    
    function f_prepare_mapem(
                             out template (value) Payload p_payload
    ) runs on ItsRSUsSimulator {
        
        p_payload := {}; // FIXME To be developped
        
    }
    
    function f_prepare_spatem(
                              out template (value) Payload p_payload
    ) runs on ItsRSUsSimulator {
        
        p_payload := {}; // FIXME To be developped
        
    }
    
    function f_prepare_ivim(
                              out template (value) Payload p_payload
    ) runs on ItsRSUsSimulator {
        
        p_payload := {}; // FIXME To be developped
        
    }
    
    function f_adaptPayload(
                            in template (value) octetstring p_finalPayload,
                            in template (value) BtpPortId  p_destPort,
                            in template (value) BtpPortId  p_srcPort := 0
    ) return template (value) Payload {
        var template (value) Payload v_payload;
        
        if(PX_GN_UPPER_LAYER == e_any) {
            v_payload := { decodedPayload := omit, rawPayload := p_finalPayload};
            return v_payload;
        }
        
        if(PX_GN_UPPER_LAYER == e_ipv6) {
            log("*** " & testcasename() & ": INCONC: Layer IPv6 not supported ***");
            setverdict(inconc);
            stop;
        }
        
        if(PX_GN_UPPER_LAYER == e_btpA) {
            v_payload := { 
                decodedPayload := { 
                    btpPacket := m_btpAWithPorts(
                        p_destPort,
                        p_srcPort,
                        { 
                            decodedPayload := omit, 
                            rawPayload := p_finalPayload 
                        }
                    )
                },
                rawPayload := ''O
            };
            return v_payload;
        }
        
        if(PX_GN_UPPER_LAYER == e_btpB) {
            v_payload := { 
                decodedPayload := { 
                    btpPacket := m_btpBWithPorts(
                        p_destPort,
                        p_srcPort,
                        { 
                            decodedPayload := omit, 
                            rawPayload := p_finalPayload 
                        }
                    )
                }, 
                rawPayload := ''O
            };
            return v_payload;
        }
        
        return v_payload;
    }
    
    function f_send(
                    in template (value) Payload p_payload
    ) runs on ItsRSUsSimulator {
        var GeoNetworkingPdu v_geoNetworkingPdu;
        
        v_geoNetworkingPdu := valueof(m_geoNwPdu( // FIXME Use PIXIT parameter to get a fully configurable template
            m_geoNwBroadcastPacket_payload( // TODO modifes 'template (value) GnNonSecuredPacket m_geoNwBroadcastPacket' to set the field
                vc_longPosVectorRsu,
                f_incLocalSeqNumber(),
                f_geoArea2GeoBroadcastArea(vc_geoArea),
                -,
                -,
                valueof(p_payload)
            ),
            m_defaultLifetime,
            c_defaultHopLimit
        ));
        f_sendGeoNetMessage(valueof(m_geoNwReq_linkLayerBroadcast(v_geoNetworkingPdu)));
    }
    
    function f_processSrem(
                           in GeoNetworkingPdu p_geoNetworkingPdu
    ) runs on ItsRSUsSimulator {
garciay's avatar
garciay committed
298
        log("SREM=", p_geoNetworkingPdu)
garciay's avatar
garciay committed
299
300
301
302
303
304
305
306
307
308
309
310
311
        // TODO Process message, and send SSEM 
    }
    
    function f_incLocalSeqNumber() runs on ItsRSUsSimulator return UInt16 {
        vc_localSeqNumber := (vc_localSeqNumber + 1) mod 65536;
        return vc_localSeqNumber;
    }
    
    function f_getDenmSequenceNumber() runs on ItsRSUsSimulator return SequenceNumber {
        return 12345; // FIXME To be refined
    }
    
} // End of module ItsRSUsSimulator_Functions