///////////////////////////////////////////////////////////////////////////////
//
// 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:               GTPU_Types.ttcn
//  Rev:                R2A
//  Prodnr:             CNL 113 843
//  Contact:            http://ttcn.ericsson.se
//  Reference:          3GPP TS 29.060 v13.5.0, 3GPP TS 29.281 v13.2.0
//
//  This module contains the GTP-U (General Packet Radio Servive Protocol
//   Tunnelling Protocol - User Plane)

module GTPU_Types {

import from General_Types all;

// external encoding/decoding functions
external function enc_PDU_GTPU(in PDU_GTPU gtpu_pdu) return octetstring
with { extension "prototype(convert)"
       extension "encode(RAW)"
}

external function dec_PDU_GTPU(in octetstring udp_pdu) return PDU_GTPU

external function dec_PDU_GTPU_ext(in octetstring udp_pdu) return PDU_GTPU_ext
with { extension "prototype(convert)"
       extension "decode(RAW)"
}


     	
//////////////////////////
// IE definition
//////////////////////////
//Private Extension - 7.7.46
type record of PrivateExtension_gtpu PrivateExtension_gtpu_List;

type record PrivateExtension_gtpu {
  OCT1             type_gtpu,
  LIN2_BO_LAST     lengthf,
  OCT2             extensionID,
  octetstring      extensionValue
} with { variant "PRESENCE( type_gtpu = 'FF'O)"; 
         variant (lengthf) "LENGTHTO(extensionID, extensionValue)";};

//Recovery - 7.7.11
type record Recovery_gtpu {
  OCT1           type_gtpu,
  OCT1           restartCounter 
};

//Extension Header Type List - 7.7.40
type record ExtensionHeaderTypeList_gtpu {
  OCT1             type_gtpu,
  integer          lengthf,
  octetstring      extensionTypesList 
} with { variant (lengthf) "LENGTHTO(extensionTypesList)"; }

//Tunnel Endpoint Identifier Data I - 7.7.13
type record TeidDataI_gtpu {
  OCT1  type_gtpu,
  OCT4  teidDataI 
};

//GSN Address - 7.7.32
type record GSNAddress_gtpu
{
  OCT1            type_gtpu,
  LIN2_BO_LAST	  lengthf,
  octetstring     gSNAddressValue
} with {variant (lengthf) "LENGTHTO(gSNAddressValue)";};

//////////////////////////
// Message definition
//////////////////////////
// Echo Request - 7.2.1
type record EchoRequest_IEs {
  PrivateExtension_gtpu_List  private_extension_gtpu  optional
} 

// Echo Response - 7.2.2
type record EchoResponse_IEs {
  Recovery_gtpu  	  recovery_gtpu,
  PrivateExtension_gtpu_List   private_extension_gtpu  optional
} 
  
//Error Indication -  3GPP TS 29.281 v13.2.0 - 7.3.1
type record ErrorIndication_IEs {
  TeidDataI_gtpu   	  teidDataI_gtpu,
  GSNAddress_gtpu         gSNAddress_gtpu,
  PrivateExtension_gtpu_List   private_extension_gtpu  optional
}

//Supported Extension Headers Notification - 7.2.4
type record SupportedExtensionHeadersNotification_IEs {
  ExtensionHeaderTypeList_gtpu extensionHeaderTypeList_gtpu
};

// 3GPP TS 29.281 v9.3.0 - 7.3.2
type record EndMarker_IEs{
  PrivateExtension_gtpu_List  private_extension_gtpu  optional
} 

//G PDU - 9.3.1
type record G_PDU_IEs {
  octetstring  data
};


type union GTPU_IEs {
  EchoRequest_IEs                             echoRequest_IEs,
  EchoResponse_IEs                            echoResponse_IEs,
  ErrorIndication_IEs                         errorIndication_IEs,
  SupportedExtensionHeadersNotification_IEs   suppExtHeadersNotif_IEs,
  EndMarker_IEs                               endMarker_IEs,
  G_PDU_IEs                                   g_PDU_IEs
};


//////////////////////////
// Extension Header definition
//////////////////////////
type record GTPU_ExtensionHeader {
  integer		lengthfield,
  octetstring 		content,
  OCT1            nextExtHeader
} with {
         variant (lengthfield) "LENGTHTO(lengthfield,content,nextExtHeader)";
         variant (lengthfield) "UNIT(32)";        
       }

type record of GTPU_ExtensionHeader GTPU_ExtensionHeader_List;

type record GTPU_Header_optional_part {
  OCT2                       sequenceNumber,
  OCT1                       npduNumber,
  OCT1                       nextExtHeader,
  GTPU_ExtensionHeader_List  gTPU_extensionHeader_List optional
} 
   

//////////////////////////
// PDU definition
//////////////////////////
type record PDU_GTPU {
  BIT1             pn_bit,
  BIT1             s_bit,
  BIT1             e_bit,
  BIT1             spare,
  BIT1             pt,
  BIT3             version,
  OCT1             messageType,
  LIN2_BO_LAST     lengthf,
  OCT4             teid,
  GTPU_Header_optional_part opt_part optional,
  GTPU_IEs         gtpu_IEs
} with { 
    variant (lengthf)  "LENGTHTO(opt_part, gtpu_IEs)";
    variant (opt_part) "PRESENCE({pn_bit = '1'B, s_bit = '1'B, e_bit = '1'B})";
    variant (gtpu_IEs) "CROSSTAG( echoRequest_IEs,     messageType = '01'O;
                                  echoResponse_IEs,    messageType = '02'O;
                                  errorIndication_IEs, messageType = '1A'O;
                                  suppExtHeadersNotif_IEs, messageType = '1F'O;
                                  endMarker_IEs,       messageType = 'FE'O;
                                  g_PDU_IEs,           messageType = 'FF'O)";
       };


type record PDU_GTPU_ext {
  PDU_GTPU gtpu_pdu,
  octetstring extraOctets
} with {
  variant "" ;
};

}//end of module
with {
extension "version R2A"
encode "RAW"
}

