///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2000-2023 Ericsson Telecom AB
//
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v2.0
// which accompanies this distribution, and is available at
// https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
///////////////////////////////////////////////////////////////////////////////
//
//  File:         MTP3asp_Types.ttcn
//  Description:  CCSS7 Message Transfer Part primitive (ASP) definitions
//                according to specification ITU-T SS7 MTP3,
//  Reference:    ITU-T Recommendation Q.704, RFC3332, ANSI T.1.111.1-2001, TCC
//  Rev:          R12A
//  Prodnr:       CNL 113 337
//  Updated:      2007-09-17
//  Contact:      http://ttcn.ericsson.se
//
module MTP3asp_Types.objid
  {
    itu_t(0) identified_organization (4) etsi(0) reserved(127)
    etsi_identified_organization(0) ericsson(5) testing (0)
    generic(0) mtp3(0) v96(3) aspDefinitions(3) patchNo(0)
  }

{//start of the module

// *************************************************************************
//  External encoding/decoding functions
// *************************************************************************

external function enc_MTP3_to_M3UAserver_msg (in MTP3_to_M3UAserver_msg pdu)
  return octetstring
  with { extension "prototype(convert)"
         extension "encode(RAW)"
       };

external function dec_MTP3_to_M3UAserver_msg(in octetstring stream)
   return MTP3_to_M3UAserver_msg
  with { extension "prototype(convert)"
         extension "decode(RAW)"
       };


// *************************************************************************
// *  Type Definitions Part                                                *
// *************************************************************************
group Types
{
  group MessageTypes
  {
    group ASPs
    {
    //***********************************************************************
    //*  ASP type definitions                                               *
    //*          Note, that ASP types shall be TTCN-3 definitions to allow  *
    //*          the use of anytype in the data field                       *
    //***********************************************************************

      type record MTP3_Field_sio
      {
        bitstring ni   length(2),
        bitstring prio length(2),
        bitstring si   length(4)
      } with { variant "FIELDORDER(msb)";
             };

      type record ASP_MTP3_TRANSFERind
      {
        MTP3_Field_sio    sio,
        integer           opc,
        integer           dpc,
        integer           sls,
        octetstring       data
      } with { variant (opc) "BYTEORDER(last), FIELDLENGTH(32)";
               variant (dpc) "BYTEORDER(last), FIELDLENGTH(32)";
               variant (sls) "FIELDLENGTH(8)"
             };

      type record ASP_MTP3_PAUSE
      {
        integer           affected_dpc
      } with { variant (affected_dpc) "BYTEORDER(last), FIELDLENGTH(32)";
             };

      type record ASP_MTP3_RESUME
      {
        integer           affected_dpc
      } with { variant (affected_dpc) "BYTEORDER(last), FIELDLENGTH(32)";
             };

      type record ASP_MTP3_STATUS
      {
        integer           affected_dpc,
        integer           cause, /* Q.704 2.4.2 */
        integer           user optional,
        integer           congestion_level optional
      } with { variant (affected_dpc) "BYTEORDER(last), FIELDLENGTH(32)";
               variant (user) "BYTEORDER(last), FIELDLENGTH(32)";
               variant (cause) "BYTEORDER(last), FIELDLENGTH(32)";
               variant (congestion_level) "BYTEORDER(last), FIELDLENGTH(32)";
             };

      type record ASP_MTP3_TRANSFERreq
      {
        MTP3_Field_sio    sio,
        integer           opc,
        integer           dpc,
        integer           sls,
        octetstring       data
      } with { variant (opc) "BYTEORDER(last), FIELDLENGTH(32)";
               variant (dpc) "BYTEORDER(last), FIELDLENGTH(32)";
               variant (sls) "FIELDLENGTH(8)"
             };
    }//end group ASPs

    //***********************************************************************
    //* Type definition of the message which is sent between MTP3 test port *
    //*  and SCTP server over TCP.                                          *
    //***********************************************************************
    group MTP3_SCTPserver
    {
      type record ASP_REGISTER_M3UA
      {
        integer     ni (0..3),
        integer     sut_pc,
        integer     tester_pc,
        integer     m3ua_version,
        charstring  entity
      } with { variant (ni) "FIELDLENGTH(8)";
               variant (sut_pc) "BYTEORDER(last), FIELDLENGTH(32)";
               variant (tester_pc) "BYTEORDER(last), FIELDLENGTH(32)";
               variant (m3ua_version) "FIELDLENGTH(8)"
      };


      // Possible values:
      // MTP3_to_SCTPserver_data/status:
      const integer reg_ok_status      := 0;
      const integer reg_error_status   := 1;
      const integer unreg_ok_status    := 2;
      const integer unreg_error_status := 3;

      const integer send_error_status  := 5;
      const integer kill_status        := 255;

      // MTP3_to_SCTPserver_data/pause:
      const integer SCTP_COMLOST_pause := 0;
      const integer M3UA_ASPDN_pause   := 1;
      const integer M3UA_ASPIA_pause   := 2;

      // MTP3_to_SCTPserver_data/resume:
      const integer ok_resume := 0;

      type union MTP3_to_SCTPserver_data
      {
        ASP_MTP3_TRANSFERind transfer_ind,
        ASP_MTP3_TRANSFERreq transfer_req,
        ASP_REGISTER_M3UA    register,
        integer              unregister (0..255),
        integer              status (0..255),
        integer              pause (0..255),
        integer              resume (0..255)
      }

      // MTP3_to_M3UAserver_msg/msgType:
      const integer transfer_ind_msgType := 0;
      const integer transfer_req_msgType := 1;
      const integer register_msgType     := 2;
      const integer unregister_msgType   := 3;
      const integer status_msgType       := 4;
      const integer pause_msgType        := 5;
      const integer resume_msgType       := 6;

      type record MTP3_to_M3UAserver_msg
      {
        integer                 msgType (0..255),
        integer                 msgLength,
        MTP3_to_SCTPserver_data data
      } with { variant (data) "CROSSTAG(
                              transfer_ind, msgType = transfer_ind_msgType;
                              transfer_req, msgType = transfer_req_msgType;
                              register,     msgType = register_msgType;
                              unregister,   msgType = unregister_msgType;
                              status,       msgType = status_msgType;
                              pause,        msgType = pause_msgType;
                              resume,       msgType = resume_msgType )";
               variant (msgLength) "FIELDLENGTH(32)";
               variant (msgLength) "LENGTHTO(msgType,msgLength,data)";
               variant (msgLength) "BYTEORDER(last)"
             };
    }//end group MTP3_SCTPserver
  }//end group Messagetypes
} with {encode "RAW"}//Types

group Templates
{
  group MessageTemplates
  {
    group ASPtemplates
    {
    // *******************************************************************
    // *   ASP template definitions                                      *
    // *******************************************************************

    // Base templates
    // These general templates can be used as an example or as a base
    // template for other templates.
      template ASP_MTP3_TRANSFERind t_ASP_MTP3_TRANSFERind
      (
        template MTP3_Field_sio pl_SIO,
        template integer        pl_OPC,
        template integer        pl_DPC,
        template integer        pl_SLS,
        template octetstring    pl_data
      ):=
      {
        sio  := pl_SIO,
        opc  := pl_OPC,
        dpc  := pl_DPC,
        sls  := pl_SLS,
        data := pl_data
      }

      template ASP_MTP3_TRANSFERind tr_ASP_MTP3_TRANSFERind_sio
      (
       template bitstring      pl_NI,
       template bitstring      pl_PRIO,
       template bitstring      pl_SI,
       template integer        pl_OPC,
       template integer        pl_DPC,
       template integer        pl_SLS,
       template octetstring    pl_data
      ):=
      {
        sio  :=
        {
          ni := pl_NI,
          prio := pl_PRIO,
          si := pl_SI
        },
        opc  := pl_OPC,
        dpc  := pl_DPC,
        sls  := pl_SLS,
        data := pl_data
      }

      template ASP_MTP3_TRANSFERind tr_ASP_MTP3_TRANSFERind :=
      {
        sio  := ?,
        opc  := ?,
        dpc  := ?,
        sls  := ?,
        data := ?
      }

      template ASP_MTP3_TRANSFERreq t_ASP_MTP3_TRANSFERreq
      (
        MTP3_Field_sio pl_SIO,
        integer        pl_OPC,
        integer        pl_DPC,
        integer        pl_SLS,
        octetstring    pl_data
      ):=
      {
        sio  := pl_SIO,
        opc  := pl_OPC,
        dpc  := pl_DPC,
        sls  := pl_SLS,
        data := pl_data
      }

      template ASP_MTP3_TRANSFERreq tr_ASP_MTP3_TRANSFERreq_sio
      (
       template bitstring      pl_NI,
       template bitstring      pl_PRIO,
       template bitstring      pl_SI,
       template integer        pl_OPC,
       template integer        pl_DPC,
       template integer        pl_SLS,
       template octetstring    pl_data
      ):=
      {
        sio  :=
        {
          ni := pl_NI,
          prio := pl_PRIO,
          si := pl_SI
        },
        opc  := pl_OPC,
        dpc  := pl_DPC,
        sls  := pl_SLS,
        data := pl_data
      }

      template ASP_MTP3_TRANSFERreq tr_ASP_MTP3_TRANSFERreq :=
      {
        sio  := ?,
        opc  := ?,
        dpc  := ?,
        sls  := ?,
        data := ?
      }

      template ASP_MTP3_TRANSFERind tr_ASP_MTP3_TRANSFERind_stc :=
      {
        sio  :=
        {
          ni := '00'B,
          prio := '00'B,
          si := '0000'B
        },
        opc  := 0,
        dpc  := 0,
        sls  := 0,
        data := ?
      }

      template ASP_MTP3_TRANSFERreq t_ASP_MTP3_TRANSFERreq_stc
      ( template octetstring    pl_data ):=
      {
        sio  :=
        {
          ni := '00'B,
          prio := '00'B,
          si := '0000'B
        },
        opc  := 0,
        dpc  := 0,
        sls  := 0,
        data := pl_data
      }

      template (present) ASP_MTP3_PAUSE tr_ASP_MTP3_PAUSE
      (
        template (present) integer affected_dpc := ?
      ) :=
      {
        affected_dpc := affected_dpc
      }

      template (value) ASP_MTP3_PAUSE ts_ASP_MTP3_PAUSE
      (
        template (value) integer affected_dpc
      ) :=
      {
        affected_dpc := affected_dpc
      }

      template (present) ASP_MTP3_RESUME tr_ASP_MTP3_RESUME
      (
        template (present) integer affected_dpc := ?
      ) :=
      {
        affected_dpc := affected_dpc
      }

      template (value) ASP_MTP3_RESUME ts_ASP_MTP3_RESUME
      (
        template (value) integer affected_dpc
      ) :=
      {
        affected_dpc := affected_dpc
      }

      template (present) ASP_MTP3_STATUS tr_ASP_MTP3_STATUS
      (
        template (present) integer affected_dpc := ?,
        template (present) integer cause := ?,
        template integer user := *,
        template integer congestion_level := *
      ) :=
      {
        affected_dpc := affected_dpc,
        cause := cause,
        user := user,
        congestion_level := congestion_level
      }

      template (value) ASP_MTP3_STATUS ts_ASP_MTP3_STATUS
      (
        template (value) integer affected_dpc,
        template (value) integer cause,
        template (omit) integer user := omit,
        template (omit) integer congestion_level := omit
      ) :=
      {
        affected_dpc := affected_dpc,
        cause := cause,
        user := user,
        congestion_level := congestion_level
      }


    }//end group ASPtemplates
  }//end group Messagetemplates
}//end group Templates

}//end module


