Skip to content
LibSip_Steps.ttcn 203 KiB
Newer Older
        } // end f_awaitingNonePassOnTimeout

        /**
         * @desc function awaits REGISTER
         * @param p_register expected REGISTER request
         */
        function f_awaitingREGISTER(
            in template(present) REGISTER_Request p_register := ?
        ) runs on SipComponent  {
            var REGISTER_Request v_request;

            tc_wait.start(PX_SIP_TWAIT);
            alt {
                [] SIPP.receive(p_register) -> value v_request sender vc_sent_label {
                    tc_wait.stop;
                    f_setHeadersOnReceiptOfREGISTER(v_request);
                }
                [] tc_wait.timeout {
                    setverdict(fail);
                    f_componentStop();
                }
            }
        }

        /**
         * @desc function awaits SUBSCRIBE
         * @param p_register expected SUBSCRIBE request
         */
        function f_awaitingSUBSCRIBE(
            in template(present) SUBSCRIBE_Request p_subscribe := ?
        ) runs on SipComponent  {
            var SUBSCRIBE_Request v_request;

            tc_wait.start(PX_SIP_TWAIT);
            alt {
                [] SIPP.receive(p_subscribe) -> value v_request sender vc_sent_label {
                    tc_wait.stop;
                    f_setHeadersOnReceiptOfSUBSCRIBE(v_request);
                }
                [] SIPP.receive(mw_SUBSCRIBE_Request_Base) -> value v_request sender vc_sent_label {
                    tc_wait.stop;
                    setverdict(fail);
                    f_setHeadersOnReceiptOfSUBSCRIBE(v_request);
                // f_send200OK();
                }
            }
        }

        /**
         * @desc function awaits REGISTER and sends a 200 OK response
         * @param p_reply flag used to avoid the 200OK response sending
         */
        function f_awaitingREGISTER_sendReply(
            in template(present) REGISTER_Request p_register := ?,
            in boolean p_reply
        ) runs on SipComponent  {
            var REGISTER_Request v_request;

            tc_wait.start(PX_SIP_TWAIT);
            alt {
                [] SIPP.receive(p_register) -> value v_request sender vc_sent_label {
                    tc_wait.stop;
                    vc_request := v_request;
                    f_setHeadersOnReceiptOfREGISTER(v_request);
                    // Answer to the Request
                    if (p_reply) {
                        f_send200OK();
                    }
                }
                [] tc_wait.timeout {
                    setverdict(fail);
                    f_componentStop();
                }
            }
        }


        /**
         * @desc Function waiting for a 200 OK response
         * @param p_cSeq_s current cSeq expectation
         */
        function f_awaitingOkResponse(
            inout CSeq p_cSeq_s
        ) runs on SipComponent  {

            tc_resp.start;
            alt {
                [] SIPP.receive(mw_Response_Base(c_statusLine200, vc_callId, p_cSeq_s)) -> value vc_response {
                    tc_resp.stop;
                    f_setHeadersOnReceiptOfResponse(vc_response);
                    setverdict(pass);
                }
            }
        } // end awaitingOkResponse

        /**
         * @desc Function waiting for a response
         * @param p_Response expected response message
         */
        function f_awaitingResponse(
            in template(present) Response p_Response := ?
        ) runs on SipComponent  {
            tc_resp.start;
            a_awaitingResponse(p_Response);
        } // end f_awaitingResponse

        altstep a_awaitingResponse(
            in template(present) Response p_Response := ?
        ) runs on SipComponent {
            [] SIPP.receive(p_Response) -> value vc_response {
                tc_resp.stop;
                f_setHeadersOnReceiptOfResponse(vc_response);
            // setverdict(pass)
            }
        } // end f_awaitingResponse

        /**
         * @desc Function waiting for a response, repeat if 100 Trying is received
         * @param p_Response expected response message
         */
        function f_awaitingResponseIgnore100Trying(
            in template(present) Response p_Response := ?
        ) runs on SipComponent  {
            tc_resp.start;
            alt {
                [] SIPP.receive(p_Response) -> value vc_response {
                    tc_resp.stop;
                    f_setHeadersOnReceiptOfResponse(vc_response);
                // setverdict(pass)
                }
                [] SIPP.receive(mw_Response_Base(c_statusLine100, vc_callId, vc_cSeq)) -> value vc_response {
                    repeat;
                }
            }
        } // end f_awaitingResponseIgnore100Trying

        /**
         * @desc Function waiting for a response and send ACK on FailureResponses 4xx,5xx,6xx
         * @param p_Response expected response message
         */
        function f_awaitingResponseSendACK(
            in template(present) Response p_Response := ?
        ) runs on SipComponent  {
            tc_resp.start;
            alt {
                [] SIPP.receive(p_Response) -> value vc_response {
                    tc_resp.stop;
                    f_setHeadersOnReceiptOfResponse(vc_response);
                    LibSip_Steps.f_setHeadersACK();
                    f_SendACK(m_ACK_Request_Base(vc_requestUri, vc_callId, vc_cSeq, vc_from, vc_to, vc_via));
                    setverdict(pass);
                }
            }
        } // end f_awaitingResponse

        /**
         * @desc Function waiting for a response
         * @param p_Response expected response message
         */
        function f_awaitingResponsePassOnTimeout(
            in template(present) Response p_Response := ?
        ) runs on SipComponent  {
            tc_resp.start;
            alt {
                [] SIPP.receive(p_Response) -> value vc_response {
                    tc_resp.stop;
                    f_setHeadersOnReceiptOfResponse(vc_response);
                    vc_boo_response := true;
                // setverdict(pass)
                }
                [] tc_resp.timeout {
                    vc_boo_response := false;
                // setverdict (pass)
                }
            }
        } // end f_awaitingResponsePassOnTimeout

        /**
         * @desc Function waiting for a 200 OK response
         * @param p_cSeq_s current cSeq expectation
         */
        function f_awaitingOkResponseAndNOTIFY_sendReply(
            inout CSeq p_cSeq_s,
            in template(present) NOTIFY_Request p_MSG := ?
        ) runs on SipComponent  {

            var boolean v_received_OK := false;
            var boolean v_received_NOTIFY := false;
            var NOTIFY_Request v_MSG;
            tc_resp.start;
            tc_wait.start(PX_SIP_TWAIT);

            alt {
                [] SIPP.receive(mw_Response_Base(c_statusLine200, vc_callId, p_cSeq_s)) -> value vc_response {
                    tc_resp.stop;
                    vc_subscribed := true;
                    f_setHeadersOnReceiptOfResponse(vc_response);
                    v_received_OK := true;
                    setverdict(pass);
                    if (not (v_received_NOTIFY)) {
                        repeat;
                    }
                }
                [] SIPP.receive(p_MSG) -> value v_MSG sender vc_sent_label {
                    tc_wait.stop;
                    f_getRouteMapIntoRecordRoute(v_MSG);
                    f_setHeadersOnReceiptOfRequest(v_MSG);
                    // Answer to the NOTIFY
                    f_send200OK();
                    v_received_NOTIFY := true;
                    if (not (v_received_OK)) {
                        repeat;
                    }
                }
            }
        } // end f_awaitingOkResponseAndNOTIFY_sendReply

        /**
         * @desc await INFO request reply with 200 OK
         */
        function f_awaitingINFO_sendReply(
            in template(value) INFO_Request p_info
        ) runs on SipComponent  {
            var INFO_Request v_request;

            tc_wait.start(PX_SIP_TWAIT);
            alt {
Yann Garcia's avatar
Yann Garcia committed
                [] SIPP.receive(p_info) -> value v_request sender vc_sent_label {
                    tc_wait.stop;
                    f_setHeadersOnReceiptOfRequest(v_request);
                    // Answer to the INFO
                    f_send200OK();
                }
            }
        } // end of f_awaitingINFO_sendReply

        /**
         * @desc function awaiting for an incoming INVITE
         * @param p_request expected message
         */
Yann Garcia's avatar
Yann Garcia committed
        function f_awaitingINVITE(
3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724
            template(present) INVITE_Request p_request := ?
        ) runs on SipComponent  {
            var INVITE_Request v_INVITE_Request;

            tc_wait.start(PX_SIP_TWAIT);
            alt {
                [] SIPP.receive(p_request) -> value v_INVITE_Request sender vc_sent_label {
                    tc_wait.stop;
                    vc_ignore_invite := true;
                    vc_first_recv := true; // communication has started
                    f_setHeadersOnReceiptOfINVITE(v_INVITE_Request);
                    SIPP.send(m_Response_Base(c_statusLine100, vc_callId, vc_cSeq, vc_from, vc_to, vc_via)) to vc_sent_label;
                }
                [vc_interface_isc] SIPP.receive(mw_INVITE_Request_Base) -> value v_INVITE_Request sender vc_sent_label {
                    tc_wait.stop;
                    setverdict(fail);
                    f_setHeadersOnReceiptOfINVITE(v_INVITE_Request);
                    SIPP.send(m_Response_Base(c_statusLine100, vc_callId, vc_cSeq, vc_from, vc_to, vc_via)) to vc_sent_label;
                    // clear session - send 486 and await ACK
                    f_sendResponse(m_Response_Base(c_statusLine486, vc_callId, vc_cSeq, vc_caller_From, vc_caller_To, vc_via));
                    f_awaitingACK(mw_ACK_Request_Base(?));
                    // await 486 which go towards and send ACK
                    f_awaitingResponse(mw_Response_Base(c_statusLine486, ?, ?));
                    f_SendACK(m_ACK_Request_Base(vc_requestUri, vc_callId, vc_cSeq, vc_from, vc_to, vc_via));
                    syncPort.send(m_syncClientStop);
                    stop;
                }
            }
        } // end f_awaitingINVITE

        /**
         * @desc function awaiting for an incoming INVITE
         * @param p_request expected message
         */
        function f_awaitingINVITE_No100Response(
            template(present) INVITE_Request p_request := ?
        ) runs on SipComponent  {
            var INVITE_Request v_INVITE_Request;

            tc_wait.start(PX_SIP_TWAIT);
            alt {
                [] SIPP.receive(p_request) -> value v_INVITE_Request sender vc_sent_label {
                    tc_wait.stop;
                    vc_ignore_invite := true;
                    vc_first_recv := true; // communication has started
                    f_setHeadersOnReceiptOfINVITE(v_INVITE_Request);
                // SIPP.send(m_Response_Base(c_statusLine100, vc_callId, vc_cSeq, vc_from, vc_to, vc_via)) to vc_sent_label;
                }
            }
        } // end f_awaitingInviteRequest

        /**
         * @desc function awaiting for an incoming INVITE
         * @param p_request expected message
         */
        function f_awaitingINVITE_PassOnTimeout(
            template(present) INVITE_Request p_request := ?
        ) runs on SipComponent  {
            var INVITE_Request v_INVITE_Request;

            tc_wait.start(PX_SIP_TWAIT);
            alt {
                [] SIPP.receive(p_request) -> value v_INVITE_Request sender vc_sent_label {
                    tc_wait.stop;
                    vc_ignore_invite := true;
                    vc_first_recv := true; // communication has started
                    vc_boo_request := true;
                    f_setHeadersOnReceiptOfINVITE(v_INVITE_Request);
                    SIPP.send(m_Response_Base(c_statusLine100, vc_callId, vc_cSeq, vc_from, vc_to, vc_via)) to vc_sent_label;
                }
                [] tc_wait.timeout {
                    vc_boo_request := false;
                }
            }
        } // end f_awaitingInviteRequest

        /**
         * @desc function awaiting ACK request
         */
        function f_awaitingACK(
            in template(present) ACK_Request p_ACK := ?
        ) runs on SipComponent  {
            f_awaitingACK_setHeaders(p_ACK, false);
        } // end f_awaitingACK

        /**
         * @desc function awaiting ACK request
         */
        function f_awaitingACK_setHeaders(
            in template(present) ACK_Request p_ACK := ?,
            in boolean p_setHeaders
        ) runs on SipComponent  {
            var ACK_Request v_ACK_Request;
            tc_ack.start;

            alt {
                [] SIPP.receive(p_ACK) -> value v_ACK_Request {
                    tc_ack.stop;
                    if (p_setHeaders) {
                        f_setHeadersOnReceiptOfRequest(v_ACK_Request);
                    }
                }
            }
        } // end f_awaitingACK_setHeaders

        /**
         * @desc function awaiting BYE and sending 200OK response
         * @param p_BYE expected BYE
         */
        function f_awaitingBYE(
            in template(present) BYE_Request p_BYE := ?
        ) runs on SipComponent  {
            var BYE_Request v_BYE_Request;

            tc_wait.start(PX_SIP_TWAIT);
            alt {
                [] SIPP.receive(p_BYE) -> value v_BYE_Request sender vc_sent_label {
                    tc_wait.stop;
                    vc_ignore_bye := true;
                    f_setHeadersOnReceiptOfBYE(v_BYE_Request);
                // f_send200OK();
                }
            }
        } // end f_awaitingBYE

        /**
         * @desc function awaiting BYE and sending 200OK response
         * @param p_BYE expected BYE
         */
        function f_awaitingBYE_sendReply(
            in template(present) BYE_Request p_BYE := ?
        ) runs on SipComponent  {
            var BYE_Request v_BYE_Request;

            tc_wait.start(PX_SIP_TWAIT);
            alt {
                [] SIPP.receive(p_BYE) -> value v_BYE_Request sender vc_sent_label {
                    tc_wait.stop;
                    vc_ignore_bye := true;
                    f_setHeadersOnReceiptOfBYE(v_BYE_Request);
                    f_send200OK();
                }
            }
        } // end f_awaitingBYE_sendReply

        /**
         * @desc function awaiting BYE and sending 200OK response
         * @param p_BYE expected BYE
         */
        function f_awaitingBYE_sendReply_PassOnTimeout(
            in template(present) BYE_Request p_BYE := ?
        ) runs on SipComponent  {
            var BYE_Request v_BYE_Request;

            tc_wait.start(PX_SIP_TWAIT);
            alt {
                [] SIPP.receive(p_BYE) -> value v_BYE_Request sender vc_sent_label {
                    tc_wait.stop;
                    vc_ignore_bye := true;
                    vc_boo_request := true;
                    f_setHeadersOnReceiptOfBYE(v_BYE_Request);
                    f_send200OK();
                }
                [] tc_wait.timeout {
                    vc_boo_request := false;
                }
            }
        } // end f_awaitingBYE_sendReply_PassOnTimeout

        /**
         * @desc function awaiting CANCEL
         * @param p_CANCEL expected CANCEL
         */
        function f_awaitingCANCEL(
            in template(present) CANCEL_Request p_CANCEL := ?
        ) runs on SipComponent  {
            var CANCEL_Request v_MSG;

            tc_wait.start(PX_SIP_TWAIT);
            alt {
                [] SIPP.receive(p_CANCEL) -> value v_MSG sender vc_sent_label {
                    tc_wait.stop;
                    f_setHeadersOnReceiptOfRequest(v_MSG);
                }
            }
        } // end f_awaitingCANCEL
        /**
         * @desc await MESSAGE request
         */
        function f_awaitingMESSAGE(
            in template(present) MESSAGE_Request p_MSG := ?
        ) runs on SipComponent  {
            var MESSAGE_Request v_MSG;

            tc_wait.start(PX_SIP_TWAIT);
            alt {
                [] SIPP.receive(p_MSG) -> value v_MSG sender vc_sent_label {
                    tc_wait.stop;
                    f_setHeadersOnReceiptOfRequest(v_MSG);
                }
                [] SIPP.receive(mw_MESSAGE_Request_Base) -> value v_MSG sender vc_sent_label {
                    tc_wait.stop;
                    f_setHeadersOnReceiptOfRequest(v_MSG);
                    log("*** " &__SCOPE__& ": INFO: Received MESSAGE not as expected! ***");
                    setverdict(fail);
                }
            }
        } // end of f_awaitingMESSAGE

        /**
         * @desc await MESSAGE request reply with 200 OK
         */
        function f_awaitingMESSAGE_sendReply(
        ) runs on SipComponent  {
            var MESSAGE_Request v_MSG;

            tc_wait.start(PX_SIP_TWAIT);
            alt {
                [] SIPP.receive(mw_MESSAGE_Request_Base) -> value v_MSG sender vc_sent_label {
                    tc_wait.stop;
                    f_setHeadersOnReceiptOfRequest(v_MSG);
                    // Answer to the MESSAGE
                    f_send200OK();
                }
            }
        } // end of f_awaitingMESSAGE_sendReply

        /**
         * @desc await MESSAGE request
         */
        function f_awaitingMESSAGE_sendReply_PassOnTimeout(
            in template(present) MESSAGE_Request p_MSG := ?
        ) runs on SipComponent  {
            var MESSAGE_Request v_MSG;

            tc_wait.start(PX_SIP_TWAIT);
            alt {
                [] SIPP.receive(p_MSG) -> value v_MSG sender vc_sent_label {
                    tc_wait.stop;
                    f_setHeadersOnReceiptOfRequest(v_MSG);
                    // Answer to the MESSAGE
                    // f_send200OK();
                    vc_boo_request := true;
                    f_send200OK();
                // setverdict (pass);
                }
                [] tc_wait.timeout {
                    vc_boo_request := false;
                // setverdict (pass);
                }
            }
        } // end of f_awaitingMESSAGE_PassOnTimeout

        /**
         * @desc await NOTIFY request
         */
        function f_awaitingNOTIFY(
            in template(present) NOTIFY_Request p_MSG := ?
        ) runs on SipComponent  {
            var NOTIFY_Request v_MSG;

            tc_wait.start(PX_SIP_TWAIT);
            alt {
                [] SIPP.receive(p_MSG) -> value v_MSG sender vc_sent_label {
                    tc_wait.stop;
                    f_getRouteMapIntoRecordRoute(v_MSG);
                    f_setHeadersOnReceiptOfRequest(v_MSG);
                }
            }
        } // end of f_awaitingNOTIFY

        /**
         * @desc await NOTIFY request reply with 200 OK
         */
        function f_awaitingNOTIFY_sendReply(
            in template(present) NOTIFY_Request p_MSG := ?
        ) runs on SipComponent  {
            var NOTIFY_Request v_MSG;

            tc_wait.start(PX_SIP_TWAIT);
            alt {
                [] SIPP.receive(p_MSG) -> value v_MSG sender vc_sent_label {
                    tc_wait.stop;
                    f_getRouteMapIntoRecordRoute(v_MSG);
                    f_setHeadersOnReceiptOfRequest(v_MSG);
                    // Answer to the NOTIFY
                    f_send200OK();
                }
            }
        } // end of f_awaitingNOTIFY_sendReply

        function f_awaitingNOTIFY_sendReply_postamble(
            in template(present) NOTIFY_Request p_MSG := ?
        ) runs on SipComponent  {
            var NOTIFY_Request v_MSG;

            tc_wait.start(5.0);
            alt {
                [] SIPP.receive(p_MSG) -> value v_MSG sender vc_sent_label {
                    tc_wait.stop;
                    f_getRouteMapIntoRecordRoute(v_MSG);
                    f_setHeadersOnReceiptOfRequest(v_MSG);
                    // Answer to the NOTIFY
                    f_send200OK();
                }
                [] tc_wait.timeout {
                // do nothing as receiving the Notify in de-registration is not part of the test body
                }
            }
        } // end of f_awaitingNOTIFY_sendReply_postamble

        /**
         * @desc await PRACK request reply with 200 OK
         */
        function f_awaitingPRACK_sendReply(
            in template(present) PRACK_Request p_MSG := ?
        ) runs on SipComponent  {
            var PRACK_Request v_MSG;

            tc_wait.start(PX_SIP_TWAIT);
            alt {
                [] SIPP.receive(p_MSG) -> value v_MSG sender vc_sent_label {
                    tc_wait.stop;
                    f_setHeadersOnReceiptOfRequest(v_MSG);
                    // Answer to the PRACK
                    if (isvalue(vc_request.messageBody) and ischosen(vc_request.messageBody.sdpMessageBody)) {
                        f_sendResponse(m_Response_mbody(c_statusLine200, vc_callId, vc_cSeq, vc_caller_From, vc_caller_To, vc_via, omit, f_recordroute(), m_MBody_SDP(vc_sdp_local)));
                    }
                    else {
                        f_sendResponse(m_Response_ext(c_statusLine200, vc_callId, vc_cSeq, vc_caller_From, vc_caller_To, vc_via, omit, f_recordroute()));
                    }
                }
            }
        } // end of f_awaitingPRACK_sendReply

        function f_awaitingPRACK(
            in template(present) PRACK_Request p_MSG := ?
        ) runs on SipComponent  {
            var PRACK_Request v_MSG;

            tc_wait.start(PX_SIP_TWAIT);
            alt {
                [] SIPP.receive(p_MSG) -> value v_MSG sender vc_sent_label {
                    tc_wait.stop;
                    f_setHeadersOnReceiptOfRequest(v_MSG);
                }
            }
        } // end of f_awaitingPRACK

        /**
         * @desc await PUBLISH request reply with 200 OK
         */
        function f_awaitingPUBLISH_sendReply(
            in template(present) PUBLISH_Request p_MSG := ?
        ) runs on SipComponent  {
            var PUBLISH_Request v_MSG;

            tc_wait.start(PX_SIP_TWAIT);
            alt {
                [] SIPP.receive(p_MSG) -> value v_MSG sender vc_sent_label {
                    tc_wait.stop;
                    f_setHeadersOnReceiptOfRequest(v_MSG);
                    // Answer to the PUBLISH
                    f_send200OK();
                }
            }
        } // end of f_awaitingPUBLISH_sendReply

        /**
         * @desc await UPDATE request
         */
        function f_awaitingUPDATE(
            in template(present) UPDATE_Request p_MSG := ?
        ) runs on SipComponent  {
            var UPDATE_Request v_MSG;

            tc_wait.start(PX_SIP_TWAIT);
            alt {
                [] SIPP.receive(p_MSG) -> value v_MSG sender vc_sent_label {
                    tc_wait.stop;
                    f_setHeadersOnReceiptOfRequest(v_MSG);
                }
            }
        } // end of f_awaitingUPDATE

        /**
         * @desc await UPDATE request reply with 200 OK
         */
        function f_awaitingUPDATE_sendReply(
            in template(present) UPDATE_Request p_MSG := ?
        ) runs on SipComponent  {
            var UPDATE_Request v_MSG;

            tc_wait.start(PX_SIP_TWAIT);
            alt {
                [] SIPP.receive(p_MSG) -> value v_MSG sender vc_sent_label {
                    tc_wait.stop;
                    f_setHeadersOnReceiptOfRequest(v_MSG);
                    // Answer to the UPDATE
                    if (isvalue(vc_request.messageBody) and ischosen(vc_request.messageBody.sdpMessageBody)) {
                        f_sendResponse(m_Response_mbody(c_statusLine200, vc_callId, vc_cSeq, vc_caller_From, vc_caller_To, vc_via, omit, f_recordroute(), m_MBody_SDP(vc_sdp_local)));
                    }
                    else {
                        f_sendResponse(m_Response_ext(c_statusLine200, vc_callId, vc_cSeq, vc_caller_From, vc_caller_To, vc_via, omit, f_recordroute()));
                    }
                }
            }
        } // end of f_awaitingUPDATE_sendReply


        /**
         * @desc await REFER request
         */
        function f_awaitingREFER(
            in template(present) REFER_Request p_MSG := ?
        ) runs on SipComponent  {
            var REFER_Request v_MSG;

            tc_wait.start(PX_SIP_TWAIT);
            alt {
                [] SIPP.receive(p_MSG) -> value v_MSG sender vc_sent_label {
                    tc_wait.stop;
                    f_setHeadersOnReceiptOfREFER(v_MSG);
                }
            }
        } // end of f_awaitingUPDATE



    } // end AwaitingMessage

    group SendMessage {

        /**
         * @desc send ACK message, update the route and recordRoute header fields depending on boolean flags
         * @param p_request template of the message to be sent
         */
        function f_SendACK(
            template(value) ACK_Request p_request
        ) runs on SipComponent  {
            // p_request.msgHeader.route := f_route(); // update the route header field depending on vc_boo_route
            // n/a p_request.msgHeader.recordRoute := f_recordroute(); // update the route header field depending on vc_boo_route
            SIPP.send(p_request) to vc_sent_label;
        }

        /**
         * @desc send BYE message, update the route and recordRoute header fields depending on boolean flags
         * @param p_request template of the message to be sent
         */
        function f_SendBYE(
            template(value) BYE_Request p_request
        ) runs on SipComponent  {
            SIPP.send(p_request) to vc_sent_label;
        }

        /**
         * @desc send CANCEL message
         * @param p_request template of the message to be sent
         */
        function f_SendCANCEL(
            template(value) CANCEL_Request p_request
        ) runs on SipComponent  {
            SIPP.send(p_request) to vc_sent_label;
        }

        /**
         * @desc send INFO message
         * @param p_request template of the message to be sent
         */
        function f_SendINFO(
            template(value) INFO_Request p_request
        ) runs on SipComponent  {
            f_setHeadersGeneral(vc_cSeq, "INFO"); // cseq, contact, branch, via
            SIPP.send(p_request) to vc_sent_label;
        }

        /**
         * @desc send INVITE message
         * @param p_request template of the message to be sent
         */
        function f_SendINVITE(
            template(value) INVITE_Request p_request
        ) runs on SipComponent  {
Yann Garcia's avatar
Yann Garcia committed
            log(">>> f_SendINVITE: ", p_request);
            vc_requestFor407 := valueof(p_request);
            SIPP.send(p_request) to vc_sent_label;
            vc_request := vc_requestFor407;
            if (PX_SIP_INVITE_AUTHENTICATION_ENABLED) {
                a_altstep_401or407();
            }
        }

        /**
         * @desc send PRACK message
         * @param p_request template of the message to be sent
         */
        function f_SendPRACK(
        ) runs on SipComponent  {
            var integer responseNum := 1;
            var PRACK_Request prackReq;
            if (isvalue(vc_response.msgHeader.rSeq) and 
                        isvalue(vc_response.msgHeader.rSeq.responseNum)){
                responseNum := vc_response.msgHeader.rSeq.responseNum;
            }
            vc_rAck := valueof(m_RAck(vc_response.msgHeader.rSeq.responseNum, vc_cSeq.seqNumber, vc_cSeq.method));
            f_setHeadersGeneral(vc_cSeq, "PRACK"); // cseq, contact, branch, via
            prackReq := valueof(m_PRACK_Request_Base(vc_requestUri, vc_callId, vc_cSeq, vc_from, vc_to, vc_via, vc_rAck));
            if (isvalue(vc_response.msgHeader.recordRoute)){
                prackReq.msgHeader.route := valueof(f_route());
            }
            SIPP.send(prackReq) to vc_sent_label;
        }

        /**
         * @desc send PUBLISH message
         * @param p_request template of the message to be sent
         */
        function f_SendPUBLISH(
            template(value) PUBLISH_Request p_request
        ) runs on SipComponent  {
            SIPP.send(p_request) to vc_sent_label;
        }

        /**
         * @desc send REGISTER message
         * @param p_request template of the message to be sent
         */
        function f_SendREGISTER(
            template(value) REGISTER_Request p_request
        ) runs on SipComponent  {
            SIPP.send(p_request) to vc_sent_label;
        }

        /**
         * @desc send SUBSCRIBE message
         * @param p_request template of the message to be sent
         */
        function f_SendSUBSCRIBE(
            template(value) SUBSCRIBE_Request p_request
        ) runs on SipComponent  {
            SIPP.send(p_request) to vc_sent_label;
        }

        /**
         * @desc send UPDATE message
         * @param p_request template of the message to be sent
         */
        function f_SendUPDATE(
            template(value) UPDATE_Request p_request
        ) runs on SipComponent  {
            f_setHeadersGeneral(vc_cSeq, "UPDATE"); // cseq, contact, branch, via
            p_request.msgHeader.cSeq := vc_cSeq;
            p_request.msgHeader.contact := vc_contact;
            p_request.msgHeader.via := vc_via;
            vc_requestFor407 := valueof(p_request);
            SIPP.send(p_request) to vc_sent_label;
            if (PX_SIP_INVITE_AUTHENTICATION_ENABLED) {
                a_altstep_401or407();
            }
        }

        /**
         * @desc function send MESSAGE message
         * @param p_request template of the message to be sent
         */
        function f_SendMESSAGE(
            template(value) MESSAGE_Request p_request
        ) runs on SipComponent  {
            SIPP.send(p_request) to vc_sent_label;
        }

        /**
         * @desc function send NOTIFY message
         * @param p_request template of the notify to be sent
         */
        function f_SendNOTIFY(
            template(value) NOTIFY_Request p_request
        ) runs on SipComponent  {
            SIPP.send(p_request) to vc_sent_label;
        }

        /**
         * @desc send REFER message
         * @param p_request template of the message to be sent
         */
        function f_SendREFER(
            template(value) REFER_Request p_request
        ) runs on SipComponent  {
            SIPP.send(p_request) to vc_sent_label;
        }

        /**
         * @desc send 200 OK
         */
        function f_send200OK(
        ) runs on SipComponent  {
            f_sendResponse(m_Response_Base(c_statusLine200, vc_callId, vc_cSeq, vc_caller_From, vc_caller_To, vc_via));
        }

        /**
         * @desc send response
         * @param p_request template of the message to be sent
         */
        function f_sendResponse(
            template(value) Response p_response
        ) runs on SipComponent  {
            p_response.msgHeader.route := f_route(); // update the route header field depending on vc_boo_route
            p_response.msgHeader.recordRoute := f_recordroute(); // update the route header field depending on vc_boo_route
            SIPP.send(p_response) to vc_sent_label;
        }



    } // end SendMessage

    group GlobalSteps {
        /**
         * @desc component initialization
         * @param p_cSeq_s cSeq value to be assigned to the component variable
         */
        function f_init_component(
            inout CSeq p_cSeq_s
        ) runs on SipComponent  {
            // Variables
            vc_cSeq := p_cSeq_s;

            // Defaults
            vc_def_catchSyncStop := activate(a_Sip_catchSyncStop());
            vc_default := activate(a_clearRegistration());
        }

        /**
         * @desc component termination
         */
        function f_terminate_component(
        ) runs on SipComponent  {
            log("*** " &__SCOPE__& ": INFO: component terminated - forced! ***");
            deactivate;
            stop;
        }

        /**
         * @desc component termination
         */
        function f_componentStop(
        ) runs on SipComponent  {
            syncPort.send(m_syncClientStop);
            SIPP.clear;
            stop;
        }

        /**
         * @desc function waits for particular time that allows the SUT to return to idle state
         */
        function f_awaitSUTidle(
        ) runs on SipComponent  {
            vc_ignore4xx := true; // allow 4xx in default
            tc_noAct.start;
            alt {
                [] tc_noAct.timeout {
                }
            }
        }

        /**
         * @desc function waits for particular time before next expected message
         */
        function f_wait(
            float p_time
        ) runs on SipComponent  {
            tc_noAct.start(p_time);
            alt {
                [] tc_noAct.timeout {
                }
            }
        }

        /**
         * @desc function cause termination of a PTC
         * @param p_syncPoint dummy parameter (copied from the common lib)
         */
        function f_check2Null(
            in charstring p_syncPoint
        ) runs on SipComponent  {
            // != pass does not work, because in case of "none" execution shall continue
            if (getverdict == inconc or getverdict == fail) {
                log("*** f_check2Null: INFO: Verdict evaluated to fail or inconc. Stopping test execution now ***");
                f_selfOrClientSyncAndVerdict(p_syncPoint, e_error);
            } // end if
        }

        /*
 *
 * @desc original copied from older LibCommon_VerdictControl
 */
        function f_getVerdict(
        ) return FncRetCode  {
            var FncRetCode v_ret := e_error;
            if (getverdict == pass or getverdict == none) {
                v_ret := e_success;
            }
            return v_ret;
        }



    } // end group GlobalSteps

    group Registration {

        /**
         * @desc registration and authentication with MD5
         * @param p_cSeq_s cseq parameter
         * @param p_register register template
         * @param p_auth flag indicating if authentication is needed
         * @param p_emergency Set to true in case of emergency call
         */
        function f_Registration(
            inout CSeq p_cSeq_s,
            out template(value) REGISTER_Request p_register,
            in boolean p_auth,
            in boolean p_emergency := false
        ) runs on SipComponent  {
            if (PX_SIP_REGISTRATION) {
                f_setHeaders_REGISTER(p_cSeq_s, p_emergency);
                p_register := m_REGISTER_Request_Base(vc_requestUri, vc_callId, p_cSeq_s, vc_from, vc_to, vc_via_REG, vc_contact, vc_authorization);
                f_SendREGISTER(p_register); // LibSip
                // awaiting of 401 and sending 2nd REGISTER and awaiting 200 OK REGISTER
                if (p_auth) {
                    // receiving 401 Unauthorized response.
                    // and Re-send REGISTER request with Authorization header
                    tc_resp.start;
                    alt {
                        [] SIPP.receive(mw_Response_Base(c_statusLine401, vc_callId, p_cSeq_s)) -> value vc_response {
                            tc_resp.stop;
                            f_setHeadersOnReceiptOfResponse(vc_response);
                            // set headers via, cseq and authorization
                            f_setHeaders_2ndREGISTER(p_cSeq_s);
                            p_register := m_REGISTER_Request_Base(vc_requestUri, vc_callId, p_cSeq_s, vc_from, vc_to, vc_via_REG, vc_contact, vc_authorization);
                            // Re-send protected REGISTER
                            f_SendREGISTER(p_register); // LibSip
                            // awaiting 200 OK REGISTER
                            f_awaitingOkResponse(p_cSeq_s);
                            f_getServiceRouteMapIntoRouteInRegistration(vc_response);
                        }
                        [] SIPP.receive(mw_Response_Base(c_statusLine200, vc_callId, p_cSeq_s)) -> value vc_response {
                            tc_resp.stop;
                            f_setHeadersOnReceiptOfResponse(vc_response);
                            f_getServiceRouteMapIntoRouteInRegistration(vc_response);
                            log("*** " &__SCOPE__& ": INFO: Authorization was not requested as expected ***");
                        }
                    }
                }
                else {
                    f_awaitingOkResponse(p_cSeq_s);
                    f_getServiceRouteMapIntoRouteInRegistration(vc_response);
                }
            }
        } // end function f_Registration