blob: 7a4a7e9b23e9e51acc81f289a7f5ff11f3f8df36 [file] [log] [blame]
Harald Welteac359802017-04-12 12:13:44 +02001///////////////////////////////////////////////////////////////////////////////
2// //
3// Copyright Test Competence Center (TCC) ETH 2009 //
4// //
5// The copyright to the computer program(s) herein is the property of TCC. //
6// The program(s) may be used and/or copied only with the written permission //
7// of TCC or in accordance with the terms and conditions stipulated in the //
8// agreement/contract under which the program(s) have been supplied //
9// //
10///////////////////////////////////////////////////////////////////////////////
11//
12// File: M3UA_Emulation.ttcn
13// Reference: M3UA Protocol Emulation
14// Rev: R1B01
15// Prodnr: CNL 113 537
16// Updated: 2009-01-06
17// Contact: http://ttcn.ericsson.se
18
19module M3UA_Emulation
20{
21
22modulepar
23{
24 boolean tsp_logVerbose := false;
25 float tsp_Timer := 2.0; // General timer used in M3UA emulation.
26 float tsp_ASPUP_Resend_Timer := 2.0;
27 float tsp_ASPAC_Resend_Timer := 2.0;
28 float tsp_Assoc_Restart_Timer := 60.0;
29 float tsp_Heartbeat_Timer := 30.0;
30 integer tsp_SCTP_PayloadProtocolID := 3; // 3 for M3UA.
31 boolean tsp_Enable_M3UA_Heartbeat := false; // Send SCTP packets periodically.
32 boolean tsp_SCTP_Server_Mode := false;
33 boolean tsp_M3UA_Server_Mode := false;
34}
35
36import from General_Types all;
37import from M3UA_Types all;
38import from SCTPasp_Types all;
39import from SCTPasp_PortType all;
40import from MTP3asp_Types all;
41
42type record of ASP_MTP3_TRANSFERreq TRANSFERreq_Buffer;
43
44type record SCTP_Association_Address
45{
46 integer local_sctp_port,
47 charstring local_ip_addr,
48 integer remote_sctp_port,
49 charstring remote_ip_addr
50}
51
52// Definition of M3UA_Entity which contains M3UA entity data.
53type record M3UA_Entity
54{
55 M3UA_CommStatus commStatus optional,
56 integer sCTP_Assoc_ID optional,
57 SCTP_Association_Address assoc
58}
59
60// Type for status of SCTP communication for an M3UA entity.
61type enumerated M3UA_CommStatus
62{
63 aSP_Down_initial_State (0),
64 aSP_Down_sCTP_Initialize_Done (1),
65 aSP_Down_sCTP_Associate_done (2),
66 aSP_Down_commUP_Received (3),
67 aSP_Down_ASPUP_Sent (4),
68 aSP_Inactive (5),
69 aSP_Inact_ASPAC_Sent (6),
70 aSP_Active (7) // aSPAC_Ack_Received
71}
72
73// We need an internal port to communicate with the MTP3 side.
74// internal in name
75type port MTP3asp_SP_PT_Int message
76{
77 in ASP_MTP3_TRANSFERreq;
78 out ASP_MTP3_TRANSFERind;
79 // out ASP_MTP3_PAUSE;
80 // out ASP_MTP3_RESUME;
81 // out ASP_MTP3_STATUS;
82} with {
83 extension "internal"
84}
85
86// M3UA emulation component.
87type component M3UA_CT
88{
89 var M3UA_Entity v_Entity;
90 var TRANSFERreq_Buffer v_TRANSFERreq_Buffer := {};
91
92 var ASP_SCTP v_ASP_SCTP;
93 var ASP_SCTP_SEND_FAILED v_ASP_SCTP_SEND_FAILED;
94 var ASP_SCTP_RESULT v_ASP_SCTP_RESULT;
95 var ASP_SCTP_Connected v_ASP_SCTP_Connected;
96 var ASP_SCTP_ASSOC_CHANGE v_ASP_SCTP_ASSOC_CHANGE;
97 var ASP_SCTP_SHUTDOWN_EVENT v_ASP_SCTP_SHUTDOWN_EVENT;
98
99 var PDU_M3UA v_PDU_M3UA;
100
101 // Component timers.
102 timer T_Timer := tsp_Timer;
103 timer T_ASPUP_resend := tsp_ASPUP_Resend_Timer;
104 timer T_ASPAC_resend := tsp_ASPAC_Resend_Timer;
105 timer T_Heartbeat := tsp_Heartbeat_Timer;
106 timer T_Assoc_restart := tsp_Assoc_Restart_Timer;
107
108 // Port declarations.
109 port MTP3asp_SP_PT_Int MTP3_SP_PORT; // Port towards MTP3/M3UA.
110 port SCTPasp_PT SCTP_PORT; // Port towards target through SCTP.
111}
112
113//********************************
114// Start of SCTP related templates
115//********************************
116template ASP_SCTP t_S_SCTP_Send
117 (in template integer pl_associationID,
118 in template integer pl_streamID,
119 in template octetstring pl_userData,
120 in template integer pl_protocolID) :=
121{
122 client_id := pl_associationID,
123 sinfo_stream := pl_streamID,
124 sinfo_ppid := pl_protocolID,
125 data := pl_userData
126}
127
128template ASP_SCTP_SEND_FAILED t_ASP_SCTP_SEND_FAILED
129 (in template integer pl_streamID) :=
130{
131 client_id := pl_streamID
132}
133
134template ASP_SCTP_Listen t_ASP_SCTP_Listen
135 (template charstring pl_local_hostname,
136 template integer pl_local_portnumber) :=
137{
138 local_hostname := pl_local_hostname,
139 local_portnumber := pl_local_portnumber
140}
141
142template ASP_SCTP_Connected tr_ASP_SCTP_Connected
143 (template integer pl_client_id,
144 template charstring pl_local_hostname,
145 template integer pl_local_portnumber,
146 template charstring pl_peer_hostname,
147 template integer pl_peer_portnumber) :=
148{
149 client_id := pl_client_id,
150 local_hostname := pl_local_hostname,
151 local_portnumber := pl_local_portnumber,
152 peer_hostname := pl_peer_hostname,
153 peer_portnumber := pl_peer_portnumber
154}
155
156template ASP_SCTP_ConnectFrom t_ASP_SCTP_ConnectFrom
157 (template charstring pl_local_hostname,
158 template integer pl_local_portnumber,
159 template charstring pl_peer_hostname,
160 template integer pl_peer_portnumber) :=
161{
162 local_hostname := pl_local_hostname,
163 local_portnumber := pl_local_portnumber,
164 peer_hostname := pl_peer_hostname,
165 peer_portnumber := pl_peer_portnumber
166}
167
168template ASP_SCTP_RESULT t_ASP_SCTP_RESULT
169 (template integer pl_client_id,
170 template boolean pl_error_status,
171 template charstring pl_error_message) :=
172{
173 client_id := pl_client_id,
174 error_status := pl_error_status,
175 error_message := pl_error_message
176}
177
178template ASP_SCTP_ASSOC_CHANGE tr_S_SCTP_CommunicationUp
179 (in template integer pl_associationID) :=
180{
181 client_id := pl_associationID,
182 sac_state := SCTP_COMM_UP
183}
184
185template ASP_SCTP_ASSOC_CHANGE tr_S_SCTP_CommunicationLost
186 (in template integer pl_associationID) :=
187{
188 client_id := pl_associationID,
189 sac_state := SCTP_COMM_LOST
190}
191
192template ASP_SCTP_ASSOC_CHANGE tr_S_SCTP_ShutdownComplete
193 (in template integer pl_associationID) :=
194{
195 client_id := pl_associationID,
196 sac_state := SCTP_SHUTDOWN_COMP
197}
198
199template ASP_SCTP_SHUTDOWN_EVENT tr_S_SCTP_ShutdownEvent
200 (in template integer pl_associationID) :=
201{
202 client_id := pl_associationID
203}
204
205template ASP_SCTP_ASSOC_CHANGE tr_S_SCTP_Restart
206 (in template integer pl_associationID) :=
207{
208 client_id := pl_associationID,
209 sac_state := SCTP_RESTART
210}
211
212template ASP_SCTP_ASSOC_CHANGE tr_S_SCTP_CANT_STR_ASSOC
213 (in template integer pl_associationID) :=
214{
215 client_id := pl_associationID,
216 sac_state := SCTP_CANT_STR_ASSOC
217}
218
219template ASP_SCTP tr_S_SCTP_DataArrive
220 (in template integer pl_associationID,
221 in template integer pl_streamID,
222 in template integer pl_protocolID,
223 in template PDU_SCTP pl_data) :=
224{
225 client_id := pl_associationID,
226 sinfo_stream := pl_streamID,
227 sinfo_ppid := pl_protocolID,
228 data := pl_data
229}
230
231template ASP_SCTP_Close t_ASP_SCTP_Close
232 (in template integer pl_associationID) :=
233{
234 client_id := pl_associationID
235}
236//******************************
237// End of SCTP related templates
238//******************************
239
240//*****************************
241// Start of M3UA PDU templates.
242//*****************************
243template PDU_M3UA t_PDU_M3UA_ASPUP
244 (in template M3UA_ASP_Identifier pl_aSP_Identifier,
245 in template M3UA_Info_String pl_info_String) :=
246{
247 m3UA_ASPUP := {
248 version := '01'O,
249 reserved := '00'O,
250 messageClassAndType := '0301'O,
251 messageLength := 0,
252 messageParameters := {
253 aSP_Identifier := pl_aSP_Identifier,
254 info_String := pl_info_String
255 }
256 }
257}
258
259template PDU_M3UA t_PDU_M3UA_ASPUP_Ack :=
260{
261 m3UA_ASPUP_Ack := {
262 version := '01'O,
263 reserved := '00'O,
264 messageClassAndType := '0304'O,
265 messageLength := 0,
266 messageParameters := {
267 info_String := omit
268 }
269 }
270}
271
272template PDU_M3UA t_PDU_M3UA_ASPDN :=
273{
274 m3UA_ASPDN := {
275 version := '01'O,
276 reserved := '00'O,
277 messageClassAndType := '0302'O,
278 messageLength := 0,
279 messageParameters := {
280 info_String := omit
281 }
282 }
283}
284
285template PDU_M3UA t_PDU_M3UA_ASPDN_Ack :=
286{
287 m3UA_ASPDN_Ack := {
288 version := '01'O,
289 reserved := '00'O,
290 messageClassAndType := '0305'O,
291 messageLength := 0,
292 messageParameters := {
293 info_String := omit
294 }
295 }
296}
297
298template PDU_M3UA t_PDU_M3UA_ASPAC
299 (in template M3UA_Traffic_Mode_Type pl_traffic_Mode_Type,
300 in template M3UA_Routing_Context pl_routing_Context,
301 in template M3UA_Info_String pl_info_String) :=
302{
303 m3UA_ASPAC := {
304 version := '01'O,
305 reserved := '00'O,
306 messageClassAndType := '0401'O,
307 messageLength := 0,
308 messageParameters := {
309 traffic_Mode_Type := pl_traffic_Mode_Type,
310 routing_Context := pl_routing_Context,
311 info_String := pl_info_String
312 }
313 }
314}
315
316template PDU_M3UA t_PDU_M3UA_ASPAC_Ack
317 (in template M3UA_Traffic_Mode_Type pl_traffic_mode_type,
318 in template M3UA_Routing_Context pl_routing_Context) :=
319{
320 m3UA_ASPAC_Ack := {
321 version := '01'O,
322 reserved := '00'O,
323 messageClassAndType := '0403'O,
324 messageLength := 0,
325 messageParameters := {
326 traffic_Mode_Type := pl_traffic_mode_type,
327 routing_Context := pl_routing_Context,
328 info_String := omit
329 }
330 }
331}
332
333template PDU_M3UA t_PDU_M3UA_ASPIA
334 (in template M3UA_Routing_Context pl_routing_Context,
335 in template M3UA_Info_String pl_info_String) :=
336{
337 m3UA_ASPIA := {
338 version := '01'O,
339 reserved := '00'O,
340 messageClassAndType := '0402'O,
341 messageLength := 0,
342 messageParameters := {
343 routing_Context := pl_routing_Context,
344 info_String := pl_info_String
345 }
346 }
347}
348
349template PDU_M3UA t_PDU_M3UA_ASPIA_Ack
350 (in template M3UA_Routing_Context pl_routing_Context) :=
351{
352 m3UA_ASPIA_Ack := {
353 version := '01'O,
354 reserved := '00'O,
355 messageClassAndType := '0404'O,
356 messageLength := 0,
357 messageParameters := {
358 routing_Context := pl_routing_Context,
359 info_String := omit
360 }
361 }
362}
363
364template PDU_M3UA t_PDU_M3UA_Heartbeat
365 (in template M3UA_Heartbeat_Data pl_heartbeat_Data) :=
366{
367 m3UA_BEAT := {
368 version := '01'O,
369 reserved := '00'O,
370 messageClassAndType := '0303'O,
371 messageLength := 0,
372 messageParameters := {
373 heartbeat_Data := pl_heartbeat_Data
374 }
375 }
376}
377
378template PDU_M3UA t_PDU_M3UA_Beat_Ack
379 (in template M3UA_Heartbeat_Data pl_heartbeat_Data) :=
380{
381 m3UA_BEAT_Ack := {
382 version := '01'O,
383 reserved := '00'O,
384 messageClassAndType := '0306'O,
385 messageLength := 0,
386 messageParameters := {
387 heartbeat_Data := pl_heartbeat_Data
388 }
389 }
390}
391
392template PDU_M3UA t_PDU_M3UA_DATA
393 (in template M3UA_Network_Appearance pl_network_Appearance,
394 in template M3UA_Routing_Context pl_routing_Context,
395 in template M3UA_Protocol_Data pl_protocol_Data,
396 in template M3UA_Correlation_ID pl_correlation_ID) :=
397{
398 m3UA_DATA := {
399 version := '01'O,
400 reserved := '00'O,
401 messageClassAndType := '0101'O,
402 messageLength := 0,
403 messageParameters := {
404 network_Appearance := pl_network_Appearance,
405 routing_Context := pl_routing_Context,
406 protocol_Data := pl_protocol_Data,
407 correlation_ID := pl_correlation_ID
408 }
409 }
410}
411
412template PDU_M3UA t_PDU_M3UA_DAVA
413 (in template M3UA_Network_Appearance pl_network_Appearance,
414 in template M3UA_Routing_Context pl_routing_Context,
415 in template M3UA_Affected_Point_Codes pl_affected_Point_Codes,
416 in template M3UA_Info_String pl_info_String) :=
417{
418 m3UA_DAVA := {
419 version := '01'O,
420 reserved := '00'O,
421 messageClassAndType := '0202'O,
422 messageLength := 0,
423 messageParameters := {
424 network_Appearance := pl_network_Appearance,
425 routing_Context := pl_routing_Context,
426 affected_Point_Codes := pl_affected_Point_Codes,
427 info_String := pl_info_String
428 }
429 }
430}
431//**************************
432// End of M3UA PDU templates
433//**************************
434
435//**********************************
436// Start of M3UA parameter templates
437//**********************************
438template M3UA_Protocol_Data t_M3UA_Protocol_Data
439 (template OCT4 pl_oPC,
440 template OCT4 pl_dPC,
441 template OCT1 pl_sI,
442 template OCT1 pl_nI,
443 template OCT1 pl_mP,
444 template OCT1 pl_sLS,
445 template octetstring pl_userProtocolData) :=
446{
447 tag := '0210'O,
448 lengthInd := 0,
449 oPC := pl_oPC,
450 dPC := pl_dPC,
451 sI := pl_sI,
452 nI := pl_nI,
453 mP := pl_mP,
454 sLS := pl_sLS,
455 userProtocolData := pl_userProtocolData
456}
457//********************************
458// End of M3UA parameter templates
459//********************************
460
461//***********************************
462// Dynamic part of the M3UA emulation
463//***********************************
464
465function f_M3UA_Emulation(SCTP_Association_Address pl_Boot) runs on M3UA_CT
466{
467 // Initialize parameters from the test case.
468 v_Entity.assoc := pl_Boot;
469 v_Entity.commStatus := aSP_Down_initial_State;
470
471 // At this point, we assume that the ports are already connected and mapped
472 // properly by the user.
473 log("*************************************************");
474 log("M3UA emulation initiated, the test can be started");
475 log("*************************************************");
476
477 f_Initialize_SCTP();
478
479 // Start the main function in an infinte loop.
480 f_M3UA_ScanEvents();
481}
482
483// Initialize the SCTP layer with parameters read from the configuration file.
484// We have only a single association.
485function f_Initialize_SCTP() runs on M3UA_CT
486{
487 v_Entity.commStatus := aSP_Down_sCTP_Initialize_Done;
488 if (tsp_SCTP_Server_Mode) {
489 // Send out a LISTEN message. The communication status doesn't change
490 // here.
491 SCTP_PORT.send
492 (t_ASP_SCTP_Listen(v_Entity.assoc.local_ip_addr,
493 v_Entity.assoc.local_sctp_port));
494 }
495 else {
496 // Send ConnectFrom sequentially, wait for RESULT messages.
497 f_Associate();
498 T_Assoc_restart.start;
499 }
500
501 if (tsp_SCTP_PayloadProtocolID == 3) {
502 if (not tsp_M3UA_Server_Mode) {
503 T_ASPUP_resend.start;
504 T_ASPAC_resend.start;
505 }
506 if (tsp_Enable_M3UA_Heartbeat) {
507 T_Heartbeat.start;
508 }
509 }
510}
511
512// Associate SCTP connection for a M3UA entity.
513function f_Associate() runs on M3UA_CT
514{
515 SCTP_PORT.send(t_ASP_SCTP_ConnectFrom
516 (v_Entity.assoc.local_ip_addr,
517 v_Entity.assoc.local_sctp_port,
518 v_Entity.assoc.remote_ip_addr,
519 v_Entity.assoc.remote_sctp_port));
520
521 T_Timer.start;
522 alt {
523 [] SCTP_PORT.receive(t_ASP_SCTP_RESULT(*, ?, *)) -> value v_ASP_SCTP_RESULT {
524 if (v_ASP_SCTP_RESULT.error_status) {
525 log("Connect failed: ", v_ASP_SCTP_RESULT.error_message);
526 }
527 else {
528 v_Entity.sCTP_Assoc_ID := v_ASP_SCTP_RESULT.client_id;
529 v_Entity.commStatus := aSP_Down_sCTP_Associate_done;
530 log("SCTP_ConnectResult -> connection established from: ",
531 v_Entity.assoc.local_ip_addr, ":", v_Entity.assoc.local_sctp_port,
532 " to server: ", v_Entity.assoc.remote_ip_addr, ":",
533 v_Entity.assoc.remote_sctp_port, " association #",
534 v_Entity.sCTP_Assoc_ID);
535 if (tsp_logVerbose) {
536 log("Association #", v_Entity.sCTP_Assoc_ID, " state changed to ",
537 v_Entity.commStatus);
538 }
539 }
540 T_Timer.stop;
541 }
542 [] T_Timer.timeout {
543 log("----------------------------------------------");
544 log("No response received to t_ASP_SCTP_ConnectFrom");
545 log("----------------------------------------------");
546 setverdict(fail);
547 // mtc.stop;
548 }
549 }
550}
551
552// Starts M3UA emulation execution.
553function f_M3UA_ScanEvents() runs on M3UA_CT
554{
555 var ASP_MTP3_TRANSFERreq vl_ASP_MTP3_TRANSFERreq;
556
557 alt {
558 [] MTP3_SP_PORT.receive(ASP_MTP3_TRANSFERreq : ?)
559 -> value vl_ASP_MTP3_TRANSFERreq {
560 f_Send_MTP3_TRANSFERreq(vl_ASP_MTP3_TRANSFERreq);
561 repeat;
562 }
563 [] as_SCTP_CommunicationUp()
564 [] as_SCTP_DataArrive()
565 [] as_SCTP_Connected()
566 [] as_Unexpected_SCTP_Events()
567 [] as_handleM3UA_timers()
568 [] as_handleSCTP_timers()
569 }
570}
571
572function f_Send_MTP3_TRANSFERreq(ASP_MTP3_TRANSFERreq pl_ASP_MTP3_TRANSFERreq)
573 runs on M3UA_CT
574{
575 if (v_Entity.commStatus == aSP_Active) {
576 if (tsp_SCTP_PayloadProtocolID == 3) { // M3UA
577 SCTP_PORT.send
578 (t_S_SCTP_Send
579 (v_Entity.sCTP_Assoc_ID,
580 1,
581 enc_PDU_M3UA
582 (valueof
583 (t_PDU_M3UA_DATA
584 (omit,
585 omit,
586 t_M3UA_Protocol_Data
587 (int2oct(pl_ASP_MTP3_TRANSFERreq.opc, 4), // OPC
588 int2oct(pl_ASP_MTP3_TRANSFERreq.dpc, 4), // DPC
589 bit2oct('0000'B & pl_ASP_MTP3_TRANSFERreq.sio.si), // SIO
590 bit2oct('000000'B & pl_ASP_MTP3_TRANSFERreq.sio.ni),
591 bit2oct('000000'B & pl_ASP_MTP3_TRANSFERreq.sio.prio),
592 int2oct(pl_ASP_MTP3_TRANSFERreq.sls, 1), // SLS
593 pl_ASP_MTP3_TRANSFERreq.data),
594 omit))),
595 tsp_SCTP_PayloadProtocolID));
596 }
597 else { // Non-M3UA
598 SCTP_PORT.send
599 (t_S_SCTP_Send
600 (v_Entity.sCTP_Assoc_ID,
601 1,
602 pl_ASP_MTP3_TRANSFERreq.data,
603 tsp_SCTP_PayloadProtocolID));
604 }
605 if (tsp_logVerbose) {
606 log("MTP3_SP_PORT: ASP_MTP3_TRANSFERreq received -> message sent " &
607 "via SCTP");
608 }
609 }
610 else {
611 // If the SCTP association is not yet running, we have to buffer the data
612 // messages arrived from the MTP3 side. Sending of buffered data messages
613 // should occure when the SCTP association is up and before sending the
614 // data message in reply for a new ASP_MTP3_TRANSFERreq data message. The
615 // buffer should be checked before sending.
616 v_TRANSFERreq_Buffer[sizeof(v_TRANSFERreq_Buffer)] :=
617 pl_ASP_MTP3_TRANSFERreq;
618 if (tsp_logVerbose) {
619 log("MTP3_SP_PORT: ASP_MTP3_TRANSFERreq received in an inactive state " &
620 "-> message was buffered");
621 }
622 }
623}
624
625// Handle communication up messages of users which performed associate earlier.
626// We have only one association.
627altstep as_SCTP_CommunicationUp() runs on M3UA_CT
628{
629 [] SCTP_PORT.receive(tr_S_SCTP_CommunicationUp(?))
630 -> value v_ASP_SCTP_ASSOC_CHANGE {
631 if (v_Entity.sCTP_Assoc_ID == v_ASP_SCTP_ASSOC_CHANGE.client_id) {
632 if (v_Entity.commStatus == aSP_Down_sCTP_Associate_done) {
633 v_Entity.commStatus := aSP_Down_commUP_Received;
634 if (tsp_SCTP_PayloadProtocolID != 3) { // Non-M3UA
635 v_Entity.commStatus := aSP_Active;
636 var integer v_i;
637 for (v_i := 0; v_i < sizeof(v_TRANSFERreq_Buffer); v_i := v_i + 1) {
638 log("Sending buffered message #", v_i);
639 f_Send_MTP3_TRANSFERreq(v_TRANSFERreq_Buffer[v_i]);
640 }
641 v_TRANSFERreq_Buffer := {};
642 // MTP3_SP_PORT.send(ASP_MTP3_RESUME : {});
643 }
644 if (tsp_logVerbose) {
645 log("Association #", v_Entity.sCTP_Assoc_ID, " state changed to: ",
646 v_Entity.commStatus);
647 }
648 if ((not tsp_M3UA_Server_Mode) and
649 (tsp_SCTP_PayloadProtocolID == 3)) { // M3UA
650 f_ASPUP_Sending();
651 }
652 }
653 else {
654 if (tsp_logVerbose) {
655 log("SCTP_CommunicationUp received in wrong state (i.e. not after " &
656 "SCTP_Associate is done) in state: ", v_Entity.commStatus);
657 }
658 }
659 }
660 else {
661 if (tsp_logVerbose) {
662 log("Association does not exists, received in CommunicationUp");
663 }
664 }
665 repeat;
666 }
667}
668
669// This altstep handles the data received from SCTP.
670altstep as_SCTP_DataArrive() runs on M3UA_CT
671{
672 [] SCTP_PORT.receive(tr_S_SCTP_DataArrive
673 (?, // associationID
674 ?, // streamID
675 ?, // protocolID
676 ? // data
677 )) -> value v_ASP_SCTP {
678 // Checking the identifier for the association is not necessary, because we
679 // have only only one association.
680 if (f_Assoc_Exists(v_ASP_SCTP.client_id)) {
681 if (tsp_logVerbose) {
682 log("Message received on association #", v_Entity.sCTP_Assoc_ID);
683 }
684 if (tsp_SCTP_PayloadProtocolID == 3) { // M3UA
685 v_PDU_M3UA := dec_PDU_M3UA(v_ASP_SCTP.data);
686 f_handle_M3UA_msg(v_PDU_M3UA);
687 }
688 else { // Non-M3UA
689 f_handle_nonM3UA_msg(v_ASP_SCTP.data);
690 }
691 }
692 else{
693 log("Message received on unknown association #", v_Entity.sCTP_Assoc_ID,
694 " -> closing connection");
695 SCTP_PORT.send(t_ASP_SCTP_Close(v_Entity.sCTP_Assoc_ID));
696 log("SCTP connection closed");
697 }
698 repeat;
699 }
700}
701
702// Handle the SCTP connected messages. It is sent from the SCTP side and it
703// signals, that we're on the right track to create the association. This is
704// for server mode.
705altstep as_SCTP_Connected() runs on M3UA_CT
706{
707 [tsp_SCTP_Server_Mode] SCTP_PORT.receive(tr_ASP_SCTP_Connected(?, ?, ?, ?, ?))
708 -> value v_ASP_SCTP_Connected {
709 // Message from the configured endpoint.
710 if ((v_ASP_SCTP_Connected.local_portnumber ==
711 v_Entity.assoc.local_sctp_port) and
712 (v_ASP_SCTP_Connected.local_hostname ==
713 v_Entity.assoc.local_ip_addr) and
714 (v_ASP_SCTP_Connected.peer_portnumber ==
715 v_Entity.assoc.remote_sctp_port) and
716 (v_ASP_SCTP_Connected.peer_hostname ==
717 v_Entity.assoc.remote_ip_addr)) {
718 v_Entity.sCTP_Assoc_ID := v_ASP_SCTP_Connected.client_id;
719 v_Entity.commStatus := aSP_Down_sCTP_Associate_done;
720 log("ASP_SCTP_Connected -> accepted connection from client: ",
721 v_ASP_SCTP_Connected.peer_hostname, ":",
722 v_ASP_SCTP_Connected.peer_portnumber, " on server: ",
723 v_ASP_SCTP_Connected.local_hostname, ":",
724 v_ASP_SCTP_Connected.local_portnumber, " with association #",
725 v_Entity.sCTP_Assoc_ID);
726 }
727 else {
728 log("ASP_SCTP_Connected -> connection from unknown client: ",
729 v_ASP_SCTP_Connected.peer_hostname, ":",
730 v_ASP_SCTP_Connected.peer_portnumber);
731 }
732 repeat;
733 }
734}
735
736// Handle error messages of users.
737altstep as_Unexpected_SCTP_Events() runs on M3UA_CT
738{
739 // Handle communications lost message. State of user with given index jumps
740 // back to initial state and stays there. That user will not be able to
741 // communicate anymore.
742 [] SCTP_PORT.receive(tr_S_SCTP_CommunicationLost(?))
743 -> value v_ASP_SCTP_ASSOC_CHANGE {
744 if (f_Assoc_Exists(v_ASP_SCTP_ASSOC_CHANGE.client_id)) {
745 if (v_Entity.commStatus == aSP_Active) {
746 // MTP3_SP_PORT.send(ASP_MTP3_PAUSE : {});
747 }
748 v_Entity.commStatus := aSP_Down_sCTP_Initialize_Done;
749 v_Entity.sCTP_Assoc_ID := omit;
750 if (tsp_logVerbose) {
751 log("SCTP_CommunicationLost received");
752 log("Association #", v_Entity.sCTP_Assoc_ID, " cleared, state " &
753 "changed to: ", v_Entity.commStatus);
754 }
755 }
756 else {
757 if (tsp_logVerbose) {
758 log("Association does not exist, received in CommunicationLost");
759 }
760 }
761 repeat;
762 }
763 [] SCTP_PORT.receive(tr_S_SCTP_ShutdownComplete(?))
764 -> value v_ASP_SCTP_ASSOC_CHANGE {
765 if (f_Assoc_Exists(v_ASP_SCTP_ASSOC_CHANGE.client_id)) {
766 if (v_Entity.commStatus == aSP_Active) {
767 // MTP3_SP_PORT.send(ASP_MTP3_PAUSE : {});
768 }
769 v_Entity.commStatus := aSP_Down_sCTP_Initialize_Done;
770 if (tsp_logVerbose) {
771 log("SCTP_ShutdownComplete received");
772 log("Association #", v_Entity.sCTP_Assoc_ID, " state changed to: ",
773 v_Entity.commStatus);
774 }
775 }
776 else {
777 if (tsp_logVerbose) {
778 log("Association does not exist, received in ShutdownComplete");
779 }
780 }
781 repeat;
782 }
783 [] SCTP_PORT.receive(tr_S_SCTP_ShutdownEvent(?))
784 -> value v_ASP_SCTP_SHUTDOWN_EVENT {
785 if (f_Assoc_Exists(v_ASP_SCTP_SHUTDOWN_EVENT.client_id)) {
786 if (v_Entity.commStatus == aSP_Active) {
787 // MTP3_SP_PORT.send(ASP_MTP3_PAUSE : {});
788 }
789 v_Entity.commStatus := aSP_Down_sCTP_Initialize_Done;
790 if (tsp_logVerbose) {
791 log("SCTP_ShutdownEvent received");
792 log("Association #", v_Entity.sCTP_Assoc_ID, " state changed to: ",
793 v_Entity.commStatus);
794 }
795 }
796 else {
797 if (tsp_logVerbose) {
798 log("Association does not exist, received in ShutdownEvent");
799 }
800 }
801 repeat;
802 }
803 [] SCTP_PORT.receive(tr_ASP_SCTP_Connected(?, ?, ?, ?, ?))
804 -> value v_ASP_SCTP_Connected {
805 log("Unexpected ASP_SCTP_Connected");
806 repeat;
807 }
808 [] SCTP_PORT.receive(tr_S_SCTP_Restart(?)) -> value v_ASP_SCTP_ASSOC_CHANGE {
809 if (f_Assoc_Exists(v_ASP_SCTP_ASSOC_CHANGE.client_id)) {
810 log("SCTP_Restart received");
811 v_Entity.commStatus := aSP_Down_commUP_Received;
812 if (tsp_logVerbose) {
813 log("Association #", v_Entity.sCTP_Assoc_ID, " state changed to: ",
814 v_Entity.commStatus);
815 }
816 }
817 else {
818 if (tsp_logVerbose) {
819 log("Association does not exist, received in SCTP_Restart");
820 }
821 }
822 repeat;
823 }
824 [] SCTP_PORT.receive(t_ASP_SCTP_SEND_FAILED(?))
825 -> value v_ASP_SCTP_SEND_FAILED {
826 log("SCTP_Send failed for association #", v_Entity.sCTP_Assoc_ID);
827 if (f_Assoc_Exists(v_ASP_SCTP_SEND_FAILED.client_id)) {
828 // Daemon sends an error status message here.
829 // MTP3_SP_PORT.send(ASP_MTP3_PAUSE : {});
830 }
831 else {
832 log("Send error received for association that doesn't exist");
833 }
834 repeat;
835 }
836 [] SCTP_PORT.receive(tr_S_SCTP_CANT_STR_ASSOC(?)) {
837 repeat;
838 }
839 [] SCTP_PORT.receive {
840 repeat;
841 }
842}
843
844// After reception of SCTP_CommunicationUp M3UA ASPUP/ASPAC is resent by the
845// entity if it didn't receive ASPUP_Ack/ASPAC_Ack.
846altstep as_handleM3UA_timers() runs on M3UA_CT
847{
848 [] T_ASPUP_resend.timeout {
849 if ((v_Entity.commStatus == aSP_Down_commUP_Received) or
850 (v_Entity.commStatus == aSP_Down_ASPUP_Sent)) {
851 // Try to send ASPUP again.
852 SCTP_PORT.send
853 (t_S_SCTP_Send
854 (v_Entity.sCTP_Assoc_ID,
855 0,
856 enc_PDU_M3UA(valueof(t_PDU_M3UA_ASPUP(omit, omit))),
857 tsp_SCTP_PayloadProtocolID));
858 v_Entity.commStatus := aSP_Down_ASPUP_Sent;
859 if (tsp_logVerbose) {
860 log("Association #", v_Entity.sCTP_Assoc_ID, " state changed to: ",
861 v_Entity.commStatus);
862 }
863 }
864 T_ASPUP_resend.start;
865 repeat;
866 }
867
868 [] T_ASPAC_resend.timeout {
869 if ((v_Entity.commStatus == aSP_Inactive) or
870 (v_Entity.commStatus == aSP_Inact_ASPAC_Sent)) {
871 SCTP_PORT.send
872 (t_S_SCTP_Send
873 (v_Entity.sCTP_Assoc_ID,
874 0,
875 enc_PDU_M3UA(valueof(t_PDU_M3UA_ASPAC(omit, omit, omit))),
876 tsp_SCTP_PayloadProtocolID));
877 v_Entity.commStatus := aSP_Inact_ASPAC_Sent;
878 if (tsp_logVerbose) {
879 log("Association #", v_Entity.sCTP_Assoc_ID, " state changed to: ",
880 v_Entity.commStatus);
881 }
882 }
883 T_ASPAC_resend.start;
884 repeat;
885 }
886
887 [tsp_Enable_M3UA_Heartbeat] T_Heartbeat.timeout {
888 if (v_Entity.commStatus == aSP_Active) {
889 SCTP_PORT.send
890 (t_S_SCTP_Send
891 (v_Entity.sCTP_Assoc_ID,
892 0,
893 enc_PDU_M3UA(valueof(t_PDU_M3UA_Heartbeat(omit))),
894 tsp_SCTP_PayloadProtocolID));
895 if (tsp_logVerbose) {
896 log("Heartbeat sent to association #", v_Entity.sCTP_Assoc_ID);
897 }
898 }
899 T_Heartbeat.start;
900 repeat;
901 }
902}
903
904// Handles SCTP timer events. In server mode we don't associate.
905altstep as_handleSCTP_timers() runs on M3UA_CT
906{
907 [not tsp_SCTP_Server_Mode] T_Assoc_restart.timeout {
908 if (v_Entity.commStatus == aSP_Down_sCTP_Initialize_Done) {
909 f_Associate();
910 }
911 T_Assoc_restart.start;
912 repeat;
913 }
914}
915
916// After reception of SCTP CommunicationUp messages M3UA ASPUP is sent by
917// every entity and the M3UA ASPUP_Ack is received by every entity.
918function f_ASPUP_Sending() runs on M3UA_CT
919{
920 SCTP_PORT.send
921 (t_S_SCTP_Send
922 (v_Entity.sCTP_Assoc_ID,
923 0, // streamID
924 enc_PDU_M3UA(valueof(t_PDU_M3UA_ASPUP(omit, omit))),
925 tsp_SCTP_PayloadProtocolID));
926 v_Entity.commStatus := aSP_Down_ASPUP_Sent;
927 if (tsp_logVerbose) {
928 log("M3UA_ASPUP sent");
929 log("Association #", v_Entity.sCTP_Assoc_ID, " state changed to: ",
930 v_Entity.commStatus);
931 }
932}
933
934
935// Test if an association with assocID exists or not. We have only one
936// association at the moment, we just check if the given assocID is the same,
937// that is associated with our single entity. If we would have more entities
938// in a table, the index of it should be returned instead of a boolean value.
939function f_Assoc_Exists(integer pl_assocID) runs on M3UA_CT return boolean
940{
941 if (v_Entity.sCTP_Assoc_ID == pl_assocID) {
942 return true;
943 }
944 else {
945 if (tsp_logVerbose) {
946 log("Association #", v_Entity.sCTP_Assoc_ID, " not found");
947 }
948 }
949 return false;
950}
951
952function f_handle_M3UA_msg(PDU_M3UA pl_PDU_M3UA) runs on M3UA_CT
953{
954 if (ischosen(pl_PDU_M3UA.m3UA_DATA)) {
955 if (v_Entity.commStatus == aSP_Active) {
956 // Send ASP_MTP3_TRANSFERind message.
957 MTP3_SP_PORT.send
958 (valueof
959 (tr_ASP_MTP3_TRANSFERind_sio
960 (substr(oct2bit(pl_PDU_M3UA.m3UA_DATA.messageParameters.protocol_Data.nI), 6, 2),
961 substr(oct2bit(pl_PDU_M3UA.m3UA_DATA.messageParameters.protocol_Data.mP), 6, 2),
962 substr(oct2bit(pl_PDU_M3UA.m3UA_DATA.messageParameters.protocol_Data.sI), 4, 4),
963 oct2int(pl_PDU_M3UA.m3UA_DATA.messageParameters.protocol_Data.oPC),
964 oct2int(pl_PDU_M3UA.m3UA_DATA.messageParameters.protocol_Data.dPC),
965 oct2int(pl_PDU_M3UA.m3UA_DATA.messageParameters.protocol_Data.sLS),
966 pl_PDU_M3UA.m3UA_DATA.messageParameters.protocol_Data.userProtocolData)));
967 if (tsp_logVerbose) {
968 log("MTP3_SP_PORT: Data received -> TRANSFERind sent");
969 }
970 }
971 else {
972 // Buffering indication messages?
973 if (tsp_logVerbose) {
974 log("MTP3_SP_PORT: Data received, no user connected -> discard");
975 }
976 }
977 }
978 else if (ischosen(pl_PDU_M3UA.m3UA_BEAT)) {
979 if (v_Entity.commStatus == aSP_Active) {
980 SCTP_PORT.send
981 (t_S_SCTP_Send
982 (v_Entity.sCTP_Assoc_ID,
983 0,
984 enc_PDU_M3UA
985 (valueof
986 (t_PDU_M3UA_Beat_Ack
987 (pl_PDU_M3UA.m3UA_BEAT.messageParameters.heartbeat_Data))),
988 tsp_SCTP_PayloadProtocolID));
989 if (tsp_logVerbose) {
990 log("M3UA_BEAT received -> M3UA_BEAT_Ack sent");
991 }
992 }
993 else {
994 if (tsp_logVerbose) {
995 log("M3UA_BEAT received in wrong state");
996 }
997 }
998 }
999 else if (ischosen(pl_PDU_M3UA.m3UA_BEAT_Ack)) {
1000 if (tsp_logVerbose) {
1001 log("Received M3UA_BEAT_Ack -> discard");
1002 }
1003 }
1004 else if (ischosen(pl_PDU_M3UA.m3UA_ERR)) {
1005 if (tsp_logVerbose) {
1006 log("Received M3UA_ERR -> discard");
1007 }
1008 }
1009 else if (ischosen(pl_PDU_M3UA.m3UA_NOTIFY)) {
1010 if (tsp_logVerbose) {
1011 log("Received M3UA_NOTIFY -> discard");
1012 }
1013 }
1014 else if (ischosen(pl_PDU_M3UA.m3UA_DUNA)) {
1015 if (tsp_logVerbose) {
1016 log("Received M3UA_DUNA -> discard");
1017 }
1018 }
1019 else if (ischosen(pl_PDU_M3UA.m3UA_DAVA)) {
1020 if (tsp_logVerbose) {
1021 log("Received M3UA_DAVA -> discard");
1022 }
1023 }
1024 // In server mode ASP_M3UA_DAUD messages can be received. In response the
1025 // server must send ASP_M3UA_DAVA messages. It's not checked if we're
1026 // servers or not.
1027 else if (ischosen(pl_PDU_M3UA.m3UA_DAUD)) {
1028 if ((v_Entity.commStatus == aSP_Inactive) or
1029 (v_Entity.commStatus == aSP_Inact_ASPAC_Sent) or
1030 (v_Entity.commStatus == aSP_Active)) {
1031 // Send ASP_M3UA_DAVA message.
1032 SCTP_PORT.send
1033 (t_S_SCTP_Send
1034 (v_Entity.sCTP_Assoc_ID,
1035 0,
1036 enc_PDU_M3UA
1037 (valueof
1038 (t_PDU_M3UA_DAVA
1039 (pl_PDU_M3UA.m3UA_DAUD.messageParameters.network_Appearance,
1040 pl_PDU_M3UA.m3UA_DAUD.messageParameters.routing_Context,
1041 pl_PDU_M3UA.m3UA_DAUD.messageParameters.affected_Point_Codes,
1042 pl_PDU_M3UA.m3UA_DAUD.messageParameters.info_String))),
1043 tsp_SCTP_PayloadProtocolID));
1044 if (tsp_logVerbose) {
1045 log("M3UA_DAUD received -> DAVA sent");
1046 }
1047 }
1048 else {
1049 if (tsp_logVerbose) {
1050 log("M3UA_DAUD received in wrong state");
1051 }
1052 }
1053 }
1054 else if (ischosen(pl_PDU_M3UA.m3UA_SCON)) {
1055 if (tsp_logVerbose) {
1056 log("Received M3UA_SCON -> discard");
1057 }
1058 }
1059 else if (ischosen(pl_PDU_M3UA.m3UA_DUPU)) {
1060 if (tsp_logVerbose) {
1061 log("Received M3UA_DUPU -> discard");
1062 }
1063 }
1064 else if (ischosen(pl_PDU_M3UA.m3UA_DRST)) {
1065 if (tsp_logVerbose) {
1066 log("Received M3UA_DRST -> discard");
1067 }
1068 }
1069 // In server mode we can receive M3UA_ASPUP messages. The answer will be a
1070 // M3UA_ASPUP_Ack message to the client.
1071 else if (ischosen(pl_PDU_M3UA.m3UA_ASPUP)) {
1072 if (((v_Entity.commStatus == aSP_Down_commUP_Received) or
1073 (v_Entity.commStatus == aSP_Down_ASPUP_Sent)) and
1074 tsp_M3UA_Server_Mode) {
1075 v_Entity.commStatus := aSP_Inactive;
1076 SCTP_PORT.send
1077 (t_S_SCTP_Send
1078 (v_Entity.sCTP_Assoc_ID,
1079 0,
1080 enc_PDU_M3UA(valueof(t_PDU_M3UA_ASPUP_Ack)),
1081 tsp_SCTP_PayloadProtocolID));
1082 if (tsp_logVerbose) {
1083 log("M3UA_ASPUP received -> M3UA_ASPUP_Ack sent");
1084 log("Association #", v_Entity.sCTP_Assoc_ID, " state changed to: ",
1085 v_Entity.commStatus);
1086 }
1087 }
1088 else {
1089 if (tsp_logVerbose) {
1090 log("M3UA_ASPUP received in wrong state or the emulation is not in " &
1091 "M3UA server mode");
1092 }
1093 }
1094 }
1095 // Receives a M3UA_ASPDN message and sends a M3UA_ASPDN_Ack message in
1096 // response.
1097 else if (ischosen(pl_PDU_M3UA.m3UA_ASPDN)) {
1098 if ((v_Entity.commStatus == aSP_Inactive) or
1099 (v_Entity.commStatus == aSP_Inact_ASPAC_Sent) or
1100 (v_Entity.commStatus == aSP_Active)) {
1101 SCTP_PORT.send
1102 (t_S_SCTP_Send
1103 (v_Entity.sCTP_Assoc_ID,
1104 0,
1105 enc_PDU_M3UA(valueof(t_PDU_M3UA_ASPDN_Ack)),
1106 tsp_SCTP_PayloadProtocolID));
1107 if (v_Entity.commStatus == aSP_Active) {
1108 // MTP3_SP_PORT.send(ASP_MTP3_PAUSE : {});
1109 }
1110 v_Entity.commStatus := aSP_Down_commUP_Received;
1111 if (tsp_logVerbose) {
1112 log("M3UA_ASPDN received -> ASPDN_Ack sent");
1113 log("Association #", v_Entity.sCTP_Assoc_ID, " state changed to: ",
1114 v_Entity.commStatus);
1115 }
1116 }
1117 else {
1118 if (tsp_logVerbose) {
1119 log("ASPDN received in wrong state or the emulation is not in M3UA " &
1120 "server mode");
1121 }
1122 }
1123 }
1124 // The M3UA client receives M3UA_ASPUP_Ack messages from the server. In
1125 // response of a M3UA_ASPUP message sent by the client.
1126 else if (ischosen(pl_PDU_M3UA.m3UA_ASPUP_Ack)) {
1127 if (((v_Entity.commStatus == aSP_Down_ASPUP_Sent) or
1128 (v_Entity.commStatus == aSP_Inactive)) and
1129 not tsp_M3UA_Server_Mode) {
1130 v_Entity.commStatus := aSP_Inactive;
1131 if (tsp_logVerbose) {
1132 log("M3UA_ASPUP_Ack received -> send M3UA_ASPAC");
1133 log("Association #", v_Entity.sCTP_Assoc_ID, " state changed to: ",
1134 v_Entity.commStatus);
1135 }
1136 SCTP_PORT.send
1137 (t_S_SCTP_Send
1138 (v_Entity.sCTP_Assoc_ID,
1139 0,
1140 enc_PDU_M3UA(valueof(t_PDU_M3UA_ASPAC(omit, omit, omit))),
1141 tsp_SCTP_PayloadProtocolID));
1142 // The state changes again after sending the M3UA_ASPAC message.
1143 v_Entity.commStatus := aSP_Inact_ASPAC_Sent;
1144 if (tsp_logVerbose) {
1145 log("Association #", v_Entity.sCTP_Assoc_ID, " state changed to: ",
1146 v_Entity.commStatus);
1147 }
1148 }
1149 else {
1150 if (tsp_logVerbose) {
1151 log("M3UA_ASPUP_Ack received in wrong state or the emulation is not " &
1152 "in M3UA client mode");
1153 }
1154 }
1155 }
1156 else if (ischosen(pl_PDU_M3UA.m3UA_ASPDN_Ack)) {
1157 if (tsp_logVerbose) {
1158 log("Received M3UA_ASPDN_Ack -> discard");
1159 }
1160 }
1161 // M3UA_ASPAC messages are received on the server side. The server sends a
1162 // M3UA_ASPAC_Ack message back to the client. This step makes the
1163 // association active on both sides.
1164 else if (ischosen(pl_PDU_M3UA.m3UA_ASPAC)) {
1165 if (((v_Entity.commStatus == aSP_Inactive) or
1166 (v_Entity.commStatus == aSP_Inact_ASPAC_Sent)) and
1167 tsp_M3UA_Server_Mode) {
1168 v_Entity.commStatus := aSP_Active;
1169 if (tsp_logVerbose) {
1170 log("M3UA_ASPAC received -> M3UA_ASPAC_Ack sent");
1171 log("Association #", v_Entity.sCTP_Assoc_ID, " state changed to: ",
1172 v_Entity.commStatus);
1173 }
1174 var integer v_i;
1175 for (v_i := 0; v_i < sizeof(v_TRANSFERreq_Buffer); v_i := v_i + 1) {
1176 log("Sending buffered message #", v_i);
1177 f_Send_MTP3_TRANSFERreq(v_TRANSFERreq_Buffer[v_i]);
1178 }
1179 v_TRANSFERreq_Buffer := {};
1180 // Send M3UA_ASPAC_Ack.
1181 SCTP_PORT.send
1182 (t_S_SCTP_Send
1183 (v_Entity.sCTP_Assoc_ID,
1184 0,
1185 enc_PDU_M3UA
1186 (valueof
1187 (t_PDU_M3UA_ASPAC_Ack
1188 (pl_PDU_M3UA.m3UA_ASPAC.messageParameters.traffic_Mode_Type,
1189 pl_PDU_M3UA.m3UA_ASPAC.messageParameters.routing_Context))),
1190 tsp_SCTP_PayloadProtocolID));
1191 // MTP3_SP_PORT.send(ASP_MTP3_RESUME : {});
1192 }
1193 else {
1194 if (tsp_logVerbose) {
1195 log("M3UA_ASPAC received in wrong state or the emulation is not in " &
1196 "M3UA server mode");
1197 }
1198 }
1199 }
1200 // The client receives M3UA_ASPAC_Ack messages from the server. The
1201 // association will be activated. The buffered messages should be send here.
1202 else if (ischosen(pl_PDU_M3UA.m3UA_ASPAC_Ack)) {
1203 if (((v_Entity.commStatus == aSP_Inact_ASPAC_Sent) or
1204 (v_Entity.commStatus == aSP_Active)) and
1205 not tsp_M3UA_Server_Mode) {
1206 // MTP3_SP_PORT.send(ASP_MTP3_RESUME : {});
1207 v_Entity.commStatus := aSP_Active;
1208 if (tsp_logVerbose) {
1209 log("ASPAC_Ack received for association #", v_Entity.sCTP_Assoc_ID);
1210 log("Association #", v_Entity.sCTP_Assoc_ID, " state changed to: ",
1211 v_Entity.commStatus);
1212 }
1213 var integer v_i;
1214 for (v_i := 0; v_i < sizeof(v_TRANSFERreq_Buffer); v_i := v_i + 1) {
1215 log("Sending buffered message #", v_i);
1216 f_Send_MTP3_TRANSFERreq(v_TRANSFERreq_Buffer[v_i]);
1217 }
1218 v_TRANSFERreq_Buffer := {};
1219 }
1220 else {
1221 if (tsp_logVerbose) {
1222 log("M3UA_ASPAC_Ack received in wrong state on association #",
1223 v_Entity.sCTP_Assoc_ID, " or the emulation is not in M3UA " &
1224 "client mode");
1225 }
1226 }
1227 }
1228 // Receives a M3UA_ASPIA message and sends back a M3UA_ASPIA_Ack message in
1229 // response.
1230 else if (ischosen(pl_PDU_M3UA.m3UA_ASPIA)) {
1231 if (v_Entity.commStatus == aSP_Active) {
1232 SCTP_PORT.send
1233 (t_S_SCTP_Send
1234 (v_Entity.sCTP_Assoc_ID,
1235 0,
1236 enc_PDU_M3UA
1237 (valueof
1238 (t_PDU_M3UA_ASPIA_Ack
1239 (pl_PDU_M3UA.m3UA_ASPIA.messageParameters.routing_Context))),
1240 tsp_SCTP_PayloadProtocolID));
1241 // MTP3_SP_PORT.send(ASP_MTP3_PAUSE : {});
1242 v_Entity.commStatus := aSP_Inactive;
1243 if (tsp_logVerbose) {
1244 log("M3UA_ASPIA received -> M3UA_ASPIA_Ack sent");
1245 log("Association #", v_Entity.sCTP_Assoc_ID, " state changed to: ",
1246 v_Entity.commStatus);
1247 }
1248 }
1249 else {
1250 if (tsp_logVerbose) {
1251 log("M3UA_ASPIA received in wrong state or the emulation is not " &
1252 "running in M3UA server mode");
1253 }
1254 }
1255 }
1256 else if (ischosen(pl_PDU_M3UA.m3UA_ASPIA_Ack)) {
1257 if (tsp_logVerbose) {
1258 log("Received M3UA_ASPIA_Ack -> discard");
1259 }
1260 }
1261 else if (ischosen(pl_PDU_M3UA.m3UA_REG_REQ)) {
1262 if (tsp_logVerbose) {
1263 log("Received M3UA_REG_REQ -> discard");
1264 }
1265 }
1266 else if (ischosen(pl_PDU_M3UA.m3UA_REG_RSP)) {
1267 if (tsp_logVerbose) {
1268 log("Received M3UA_REG_RSP -> discard");
1269 }
1270 }
1271 else if (ischosen(pl_PDU_M3UA.m3UA_DEREG_REQ)) {
1272 if (tsp_logVerbose) {
1273 log("Received M3UA_DEREG_REQ -> discard");
1274 }
1275 }
1276 else if (ischosen(pl_PDU_M3UA.m3UA_DEREG_RSP)) {
1277 if (tsp_logVerbose) {
1278 log("Received M3UA_DEREG_RSP -> discard");
1279 }
1280 }
1281}
1282
1283function f_handle_nonM3UA_msg(octetstring pl_PDU) runs on M3UA_CT
1284{
1285 if (v_Entity.commStatus == aSP_Active) {
1286 // Send TRANSFERind message.
1287 MTP3_SP_PORT.send(valueof
1288 (tr_ASP_MTP3_TRANSFERind_sio
1289 ('00'B,
1290 '00'B,
1291 '0000'B,
1292 0,
1293 0,
1294 0,
1295 pl_PDU)));
1296 if (tsp_logVerbose) {
1297 log("Non-M3UA DATA received -> TRANSFERind sent");
1298 }
1299 }
1300 else {
1301 if (tsp_logVerbose) {
1302 log("DATA received, but no user connected -> discard");
1303 }
1304 }
1305}
1306
1307}