ItsRSUsSimulator_Functions.ttcn 18.9 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
    import from DSRC language "ASN.1:1997" all;
garciay's avatar
garciay committed
20
21
22
23
24
25
26
27
28
29
30
    
    // LibItsCommon
    import from LibItsCommon_Functions all;
    
    // LibItsBtp
    import from LibItsBtp_TypesAndValues all;
    import from LibItsBtp_Templates all;
    
    // LibItsDenm
    import from LibItsDenm_Templates all;
    
garciay's avatar
garciay committed
31
32
33
    // LibItsMapemSpatemm
    import from LibItsMapemSpatem_Templates all;
    
34
35
36
37
38
39
    // LibItsMapemSpatemm
    import from LibItsIvim_Templates all;
    
    // LibItsMapemSpatemm
    import from LibItsSremSsem_Templates all;
    
garciay's avatar
garciay committed
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
    // 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
68
69
            var template (omit) DENMs v_denms := omit;
            var template (omit) CAM v_cam := omit;
70
71
72
73
            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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
            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
89
//            f_initialState();
garciay's avatar
garciay committed
90
91
92
            
            // Initialisations
            vc_longPosVectorRsu := PICS_RSU_PARAMS[PX_RSU_ID - 1].longPosVector;
garciay's avatar
garciay committed
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
            // MAPEM
            if (PICS_GENERATE_MAPEM) {
                // Build the list of the MAPEM events
                v_mapem := 
                    m_mapemParm(
                        PICS_RSU_PARAMS[PX_RSU_ID - 1].stationID,
                        m_mapem(
                            f_getMsgIssueRevision(),
                            PICS_MAPEM_PARMS_RSUs[PX_RSU_ID - 1].intersections,
                            PICS_MAPEM_PARMS_RSUs[PX_RSU_ID - 1].roadSegments
                ));
                // Update revision fields
                v_mapem.map_.intersections[0].revision := f_incMsgIssueRevision();
                // TODO Add more?
            }
            // SPATEM
            if (PICS_GENERATE_SPATEM) {
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
                // Build the list of the DENM events
                for (v_counter := 0; v_counter < lengthof(PICS_SPATEM_PARMS_RSUs[PX_RSU_ID - 1]); v_counter := v_counter + 1) {
                    v_spatems[v_counter] := 
                        m_spatemParm(
                            PICS_RSU_PARAMS[PX_RSU_ID - 1].stationID,
                            m_spatem(
                                PICS_SPATEM_PARMS_RSUs[PX_RSU_ID - 1][v_counter].intersections,
                                "SignalGroupID #" & int2str(PICS_SPATEM_PARMS_RSUs[PX_RSU_ID - 1][v_counter].signalGroupID)
                    ));
                    for (var integer v_intersection := 0; v_intersection < lengthof(v_spatems[v_counter].spat.intersections); v_intersection := v_intersection + 1) {
                        vc_states[v_counter][v_intersection] := v_spatems[v_counter].spat.intersections[v_intersection].states;
                    } // End of 'for' statement
                    // TODO Build SPATEM with dynamic values
                } // End of 'for' statement
                // TODO Build SPATEM with dynamic values
garciay's avatar
garciay committed
125
126
127
            }
            // IVIM
            if (PICS_GENERATE_IVIM) {
128
129
130
131
132
133
134
135
136
137
138
139
140
                // Build the list of the MAPEM events
                v_ivim := 
                    m_ivimParm(
                        PICS_RSU_PARAMS[PX_RSU_ID - 1].stationID,
                        m_ivimStructure(
                            m_iviManagementContainer(
                                PICS_IVIM_PARMS_RSUs[PX_RSU_ID - 1].provider,
                                PICS_IVIM_PARMS_RSUs[PX_RSU_ID - 1].iviIdentificationNumber,
                                0//IviStatus_new_
                )));
                // Update ivi status
                v_ivim.ivi.mandatory.validFrom := f_getCurrentTime();
                // TODO Add more?
garciay's avatar
garciay committed
141
142
            }
            // DENM
garciay's avatar
garciay committed
143
144
            if (PICS_GENERATE_DENM) {
                // Build the list of the DENM events
145
146
147
                for (v_counter := 0; v_counter < lengthof(PICS_DENM_EVENTS_RSU[PX_RSU_ID - 1][PX_ETSI_ZONE_ID]); v_counter := v_counter + 1) {
                    var DenmEventsParmsPerZone v_denmEventsParmsPerZone := PICS_DENM_EVENTS_RSU[PX_RSU_ID - 1][PX_ETSI_ZONE_ID];
                    
garciay's avatar
garciay committed
148
149
                    v_denmParmContainers := m_denmParmContainers(
                        PICS_RSU_PARAMS[PX_RSU_ID - 1].stationID,
garciay's avatar
garciay committed
150
                        f_incDenmSequenceNumber(),
151
                        PICS_DENM_REPETITION_INTERVAL,
152
153
154
155
                        v_denmEventsParmsPerZone[v_counter].eventPosition,
                        v_denmEventsParmsPerZone[v_counter].causeCodeType,
                        v_denmEventsParmsPerZone[v_counter].eventHistory,
                        v_denmEventsParmsPerZone[v_counter].traces
garciay's avatar
garciay committed
156
157
                    );
                    v_denms[v_counter] := valueof(
garciay's avatar
garciay committed
158
159
160
161
162
163
                        m_denmPdu(
                            m_denm(
                                   v_denmParmContainers.managementContainer, 
                                   v_denmParmContainers.situationContainer,
                                   v_denmParmContainers.locationContainer
                    )));
164
165
                    if (ispresent(v_denmEventsParmsPerZone[v_counter].roadWorksContainerExtended)) {
                        v_denms[v_counter].denm.alacarte := m_alacarte(v_denmEventsParmsPerZone[v_counter].roadWorksContainerExtended);
166
                    }
167
                } // End of 'for' statement
garciay's avatar
garciay committed
168
            }
garciay's avatar
garciay committed
169
            // CAM
garciay's avatar
garciay committed
170
171
            if (PICS_GENERATE_CAM) {
                // Build the list of the CAM events
172
173
174
175
176
177
178
179
                v_cam := 
                    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
180
                );
garciay's avatar
garciay committed
181
            } 
garciay's avatar
garciay committed
182
            // Build the messages value list for this RSU
183
            vc_rsuMessagesValueList[PX_RSU_ID - 1] := 
garciay's avatar
garciay committed
184
                m_rsuProfile(
garciay's avatar
garciay committed
185
                    v_cam, 
186
                    v_denms,
garciay's avatar
garciay committed
187
                    v_mapem,
188
189
190
191
                    v_spatems,
                    v_ivim,
                    v_ssem
            );
garciay's avatar
garciay committed
192
193
194
195
196
197
198
199
200
201
202
203
            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 {
            
204
205
            vc_longPosVectorRsu := {};
            vc_geoArea := {};
206
207
            vc_rsuMessagesValueList := {};
            
garciay's avatar
garciay committed
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
            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 {
        
244
        // Update dynamic parms
garciay's avatar
garciay committed
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
        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 {
        
garciay's avatar
garciay committed
263
264
265
266
267
268
269
270
271
272
273
        p_payload := valueof(
            f_adaptPayload(
                bit2oct(
                    encvalue(
                        valueof(
                            vc_rsuMessagesValueList[PX_RSU_ID - 1].mapem
                ))),
                PICS_MAPEM_BTP_DESTINATION_PORT,
                PICS_MAPEM_BTP_SOURCE_PORT
            )
        );
garciay's avatar
garciay committed
274
275
276
    }
    
    function f_prepare_spatem(
277
                              in template (value) SPATEM p_spatem,
garciay's avatar
garciay committed
278
279
                              out template (value) Payload p_payload
    ) runs on ItsRSUsSimulator {
280
        var template (value) SPATEM v_spatem := p_spatem; // Make a copy
garciay's avatar
garciay committed
281
        
282
283
        // Rebuild SPATEM message
        for (var integer v_intersection := 0; v_intersection < lengthof(v_spatem.spat.intersections); v_intersection := v_intersection + 1) {
284
            var template (value) MovementList v_states := vc_states[PX_RSU_ID - 1][v_intersection];
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
            select (vc_spatemStatesId) {
                case (0) {
                    v_spatem.spat.intersections[v_intersection].states[0] := v_states[0];
                    v_spatem.spat.intersections[v_intersection].states[1] := v_states[1];
                    v_spatem.spat.intersections[v_intersection].states[2] := v_states[2];
                }
                case (1) {
                    v_spatem.spat.intersections[v_intersection].states[0] := v_states[1];
                    v_spatem.spat.intersections[v_intersection].states[1] := v_states[2];
                    v_spatem.spat.intersections[v_intersection].states[2] := v_states[0];
                }
                case (2) {
                    v_spatem.spat.intersections[v_intersection].states[0] := v_states[2];
                    v_spatem.spat.intersections[v_intersection].states[1] := v_states[0];
                    v_spatem.spat.intersections[v_intersection].states[2] := v_states[1];
                }
                case else {
                }
            } // End of 'select' statement
        } // End of 'for' statement
        vc_spatemStatesId := (vc_spatemStatesId + 1) mod 4; // TODO To be refined
        
        p_payload := valueof(
            f_adaptPayload(
                bit2oct(
                    encvalue(
                        valueof(
                            v_spatem
                ))),
314
315
                PICS_SPATEM_BTP_DESTINATION_PORT,
                PICS_SPATEM_BTP_SOURCE_PORT
316
317
            )
        );
garciay's avatar
garciay committed
318
319
320
321
        
    }
    
    function f_prepare_ivim(
322
                            out template (value) Payload p_payload
garciay's avatar
garciay committed
323
324
    ) runs on ItsRSUsSimulator {
        
325
326
327
328
329
330
331
332
333
334
335
        p_payload := valueof(
            f_adaptPayload(
                bit2oct(
                    encvalue(
                        valueof(
                            vc_rsuMessagesValueList[PX_RSU_ID - 1].ivim
                ))),
                PICS_IVIM_BTP_DESTINATION_PORT,
                PICS_IVIM_BTP_SOURCE_PORT
            )
        );
garciay's avatar
garciay committed
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
    }
    
    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 {
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
        log("SREM=", p_geoNetworkingPdu);
        if (ispresent(p_geoNetworkingPdu.gnPacket.packet.payload.decodedPayload)) {
            if (ispresent(p_geoNetworkingPdu.gnPacket.packet.payload.decodedPayload.btpPacket.payload.decodedPayload)) {
                if (ischosen(p_geoNetworkingPdu.gnPacket.packet.payload.decodedPayload.btpPacket.payload.decodedPayload.sremPacket)) {
                    var SignalRequestMessage v_signalRequestMessage := p_geoNetworkingPdu.gnPacket.packet.payload.decodedPayload.btpPacket.payload.decodedPayload.sremPacket.srm;
                    var template (value) Payload v_payload;
                    
                    log(v_signalRequestMessage);
                    // Build response
                    // TODO v_ssem.ssm.status
                    v_payload := valueof(
                        f_adaptPayload(
                            bit2oct(
                                encvalue(
                                    valueof(
garciay's avatar
garciay committed
431
432
433
                                        m_ssem(
                                            v_signalRequestMessage
                            )))),
434
435
436
437
438
439
440
441
                            PICS_SSEM_BTP_DESTINATION_PORT,
                            PICS_SSEM_BTP_SOURCE_PORT
                        )
                    );
                    
                } // else, ignore message
            } // else, ignore message
        } // else, ignore message
garciay's avatar
garciay committed
442
443
444
445
446
447
448
449
        // TODO Process message, and send SSEM 
    }
    
    function f_incLocalSeqNumber() runs on ItsRSUsSimulator return UInt16 {
        vc_localSeqNumber := (vc_localSeqNumber + 1) mod 65536;
        return vc_localSeqNumber;
    }
    
garciay's avatar
garciay committed
450
451
452
453
454
455
456
457
458
459
460
461
462
463
    function f_incMsgIssueRevision() runs on ItsRSUsSimulator return MsgCount {
        vc_msgIssueRevision := (vc_msgIssueRevision + 1) mod 128; // See MsgCount declaration
        return vc_msgIssueRevision;
    }
    
    function f_getMsgIssueRevision() runs on ItsRSUsSimulator return MsgCount {
        return vc_msgIssueRevision;
    }
    
    function f_incDenmSequenceNumber() runs on ItsRSUsSimulator return SequenceNumber {
        vc_sequenceNumber := (vc_sequenceNumber + 1) mod 65536; // See SequenceNumber declaration
        return vc_sequenceNumber;
    }
    
garciay's avatar
garciay committed
464
    function f_getDenmSequenceNumber() runs on ItsRSUsSimulator return SequenceNumber {
garciay's avatar
garciay committed
465
        return vc_sequenceNumber;
garciay's avatar
garciay committed
466
467
468
    }
    
} // End of module ItsRSUsSimulator_Functions