///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2000-2019 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:               M2PA_Types.ttcn
//  Rev:                R1C
//  Prodnr:             CNL 113 558
//  Updated:            2013-03-04
//  Contact:            http://ttcn.ericsson.se
//  Reference:          IETF RFC 4165

module M2PA_Types {

import from General_Types all; 

//++++++++++++++++++++++++++++++++++++++++++++++++++
//Coding functions
//++++++++++++++++++++++++++++++++++++++++++++++++++
external function enc_PDU_M2PA(in PDU_M2PA pdu) return octetstring
with { extension "prototype(convert)"
       extension "encode(RAW)"
     }

external function dec_PDU_M2PA(in octetstring stream) return PDU_M2PA
with { extension "prototype(convert)"
       extension "decode(RAW)"
     }

//++++++++++++++++++++++++++++++++++++++++++++++++++
//M2PA PDUs
//++++++++++++++++++++++++++++++++++++++++++++++++++


//  M2PA_DATA PDU
//++++++++++++++++++++++++++++++++++++++++++++++++++
type record M2PA_DATA
{ 
  OCT1                        version,
  OCT1                        spare,
  OCT2                        messageClassAndType,
  integer                     messageLength,
  M2PA_Data_Message           protocolDataMessage
} with { variant (messageLength) "LENGTHTO(version,spare,messageClassAndType,
                                           messageLength,protocolDataMessage)"; 
         variant (messageLength) "FIELDLENGTH(32)";
         variant (messageLength) "BYTEORDER(last)";   
       }

type record M2PA_Data_Message
{
  OCT1                     preBSNunused,
  integer                  bsn,
  OCT1                     preFSNunused,
  integer                  fsn,
  M2PA_User_Data           protocol_Data optional
} with { variant (bsn) "FIELDLENGTH(24)";
         variant (bsn) "BYTEORDER(last)";   
         variant (fsn) "FIELDLENGTH(24)";
         variant (fsn) "BYTEORDER(last)"; 
  
       }

type record M2PA_User_Data
{
  BIT6n                    spare,
  BIT2n                    pri,
  OCT1                     sio,
  octetstring              sifOctets
} with { variant "PADDING(dword32)"; }

//  M2PA_LINK_STATUS_PDU
//++++++++++++++++++++++++++++++++++++++++++++++++++
type record M2PA_LINK_STATUS
{
  OCT1                        version,
  OCT1                        spare,
  OCT2                        messageClassAndType,
  integer                     messageLength,
  M2PA_Link_Status_Message    protocolLinkStatusMessage
} with { variant (messageLength) "LENGTHTO(version,spare,messageClassAndType,
                                           messageLength,
                                           protocolLinkStatusMessage)"; 
         variant (messageLength) "FIELDLENGTH(32)";
         variant (messageLength) "BYTEORDER(last)";   
       }


type record M2PA_Link_Status_Message
{
  OCT1                     preBSNunused,
  integer                  bsn,
  OCT1                     preFSNunused,
  integer                  fsn,
  M2PA_Link_Status         protocolLinkStatus 
} with { variant (bsn) "FIELDLENGTH(24)";
         variant (bsn) "BYTEORDER(last)";   
         variant (fsn) "FIELDLENGTH(24)";
         variant (fsn) "BYTEORDER(last)"; 
       }
 

type record M2PA_Link_Status
{
  M2UA_State               status,
  octetstring              filler optional
} with { variant "PADDING(dword32)"; }


type enumerated M2UA_State
{
  Alignment(1),
  ProvingNormal(2),
  ProvingEmergency(3),
  Ready(4),
  ProcessorOutage(5),
  ProcessorRecovered(6),
  Busy(7),
  BusyEnded(8),
  OutOfService(9)
} with { variant "FIELDLENGTH(32)"
         variant "BYTEORDER(last)";  
};

// Top level PDU
//************************************************************************
type union PDU_M2PA
{
  M2PA_DATA                                 m2PA_DATA,
  M2PA_LINK_STATUS                          m2PA_LINK_STATUS
} with { variant "TAG(
          m2PA_DATA,                        messageClassAndType = '0B01'O;    
          m2PA_LINK_STATUS,                 messageClassAndType = '0B02'O)"
       }
} with { 
extension "version R1C"
encode "RAW"}
