///////////////////////////////////////////////////////////////////////////////
//
// 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:               NS_Types.ttcn
//  Rev:                R2B
//  Prodnr:             CNL 113 578
//  Updated:            2008-01-22
//  Contact:            http://ttcn.ericsson.se
//  Reference:          3GPP TS 48.016 7.3.0
 
module NS_Types
{    // beginning of module

// This module contains the Base Station System (BSS) Serving GPRS Support
// Node (SGSN) interface  Network Sevice protocol
//  48.016 v7.3.0 with attributes for RAW encoding/decoding.
// 
                 
// History:
// ********

import from General_Types all;

external function enc_PDU_NS(in PDU_NS pdu) return octetstring
with { extension "prototype(convert)"
       extension "encode(RAW)"
     } 
                
external function dec_PDU_NS(in octetstring stream) return PDU_NS
with { extension "prototype(convert)"
       extension "decode(RAW)"
     }

type record CauseNS
{
OCT1                     iEI, 
BIT1                     ext,
LIN1_2                   lengthIndicator,
OCT1                     cause
}  with { 
        variant (lengthIndicator) "LENGTHTO (cause)";
        variant (lengthIndicator) "CROSSTAG( length1,         ext = '1'B;
                                             length2,         ext = '0'B;)";
        variant (ext,lengthIndicator) "FIELDORDER(msb)";
       }

type record NS_VCI  
{
OCT1                     iEI, 
BIT1                     ext,
LIN1_2                   lengthIndicator,
OCT2                     nS_VCI
} with { 
        variant (lengthIndicator) "LENGTHTO (nS_VCI)";
        variant (lengthIndicator) "CROSSTAG( length1,         ext = '1'B;
                                             length2,         ext = '0'B;)";
        variant (ext,lengthIndicator) "FIELDORDER(msb)";
       }

type record NS_PDU  
{
OCT1                     iEI, 
BIT1                     ext,
LIN1_2                   lengthIndicator,
octetstring              ns_PDU
} with { 
        variant (lengthIndicator) "LENGTHTO (ns_PDU)";
        variant (lengthIndicator) "CROSSTAG( length1,         ext = '1'B;
                                             length2,         ext = '0'B;)";
        variant (ext,lengthIndicator) "FIELDORDER(msb)";
       }
 
type record BVCI_NS 
{
OCT1                     iEI, 
BIT1                     ext,
LIN1_2                   lengthIndicator,
OCT2                     bVCI
} with { 
        variant (lengthIndicator) "LENGTHTO (bVCI)";
        variant (lengthIndicator) "CROSSTAG( length1,         ext = '1'B;
                                             length2,         ext = '0'B;)";
        variant (ext,lengthIndicator) "FIELDORDER(msb)";
       }       

type record ListofIP4Elements 
{
OCT1                     iEI, 
BIT1                     ext,
LIN1_2                   lengthIndicator,
IP4_Elements             iP4_Elements
}  with { 
        variant (lengthIndicator) "LENGTHTO (iP4_Elements)";
        variant (lengthIndicator) "CROSSTAG( length1,         ext = '1'B;
                                             length2,         ext = '0'B;)";
        variant (ext,lengthIndicator) "FIELDORDER(msb)";
       }       

type record IP4_Element
{
OCT4                     ipAddress,
OCT2                     uDP_Port,
OCT1                     signallingWeight,
OCT1                     dataWeight
}

type record of IP4_Element IP4_Elements;

type record ListofIP6Elements 
{
OCT1                     iEI, 
BIT1                     ext,
LIN1_2                   lengthIndicator,
IP6_Elements             iP6_Elements
}  with { 
        variant (lengthIndicator) "LENGTHTO (iP6_Elements)";
        variant (lengthIndicator) "CROSSTAG( length1,         ext = '1'B;
                                             length2,         ext = '0'B;)";
        variant (ext,lengthIndicator) "FIELDORDER(msb)";
       }       

type record IP6_Element
{
OCT16                    ipAddress,
OCT2                     uDP_Port,
OCT1                     signallingWeight,
OCT1                     dataWeight
}

type record of IP6_Element IP6_Elements;

type record IP_Address_NS
{
OCT1                     iEI, 
OCT1                     addressType,
IPAddress                ipAddress
}with {
  variant (ipAddress) "CROSSTAG
    (
      ip4Address,    addressType = '01'O;
      ip6Address,    addressType = '02'O; 
    )"
}; 
     
type union IPAddress 
{
OCT4                     ip4Address,
OCT16                    ip6Address
}

type record EndFlag
{
BIT1                     eBIT,
BIT7                     spare
}

type record ResetFlag
{
OCT1                     iEI, 
BIT1                     resetBIT,
BIT7                     spare
}

type record MaxNumberOfNSVCs
{
OCT1                     iEI, 
OCT2                     maxNumberOfNSVCs 
}

type record NumberOfIP_Endpoints 
{
OCT1                     iEI, 
OCT2                     numberOfIP_Endpoints 
}


type record NSEI_NS
{
OCT1                     iEI, 
BIT1                     ext,
LIN1_2                   lengthIndicator,
OCT2                     nSEI
} with { 
        variant (lengthIndicator) "LENGTHTO (nSEI)";
        variant (lengthIndicator) "CROSSTAG( length1,         ext = '1'B;
                                             length2,         ext = '0'B;)";
        variant (ext,lengthIndicator) "FIELDORDER(msb)";
       }       

type record NS_SDU_ControlBits
{
BIT1                     rBit,
BIT1                     cBit,
BIT6                     spare
}

//same type def as LIN2_2a in BSSGP but named differently 
type union LIN1_2
{
integer length1,
integer length2
} with {
        variant (length1) "FIELDLENGTH(7)";
        variant (length2) "FIELDLENGTH(15)";
        variant (length2) "BYTEORDER(last)";
        variant (length1,length2) "FIELDORDER(msb)"
      }        


// PDUs ************************************************************


type record PDU_NS_Alive
{
OCT1                     nsPduType 
}

type record PDU_NS_Alive_Ack
{
OCT1                     nsPduType
}

type record PDU_NS_Block
{
OCT1                     nsPduType,
CauseNS                  causeNS,                        //TLV
NS_VCI                   nS_VCI                          //TLV
}

type record PDU_NS_Block_Ack
{
OCT1                     nsPduType,
NS_VCI                   nS_VCI                          //TLV
}

type record PDU_NS_Reset
{
OCT1                     nsPduType,
CauseNS                  causeNS,                        //TLV
NS_VCI                   nS_VCI,                         //TLV
NSEI_NS                  nSEI_NS                         //TLV      
}

type record PDU_NS_Reset_Ack
{
OCT1                     nsPduType,
NS_VCI                   nS_VCI,                         //TLV
NSEI_NS                  nSEI_NS                         //TLV      
}

type record PDU_NS_Status
{
OCT1                     nsPduType,
CauseNS                  causeNS,                        //TLV
NS_VCI                   nS_VCI              optional,   //TLV   
NS_PDU                   nS_PDU              optional,   //TLV
BVCI_NS                  bVCI_NS             optional,   //TLV
ListofIP4Elements        listofIP4Elements   optional,   //TLV
ListofIP6Elements        listofIP6Elements   optional    //TLV
} with { 
  variant "TAG (
                nS_VCI,                        iEI = '01'O;
                nS_PDU,                        iEI = '02'O;
                bVCI_NS,                       iEI = '03'O;
                listofIP4Elements,             iEI = '05'O;
		listofIP6Elements,             iEI = '06'O                 
        )"
}

type record PDU_NS_Unblock
{
OCT1                     nsPduType
}

type record PDU_NS_Unblock_Ack
{
OCT1                     nsPduType
}

type record PDU_NS_Unitdata
{
OCT1                     nsPduType,
NS_SDU_ControlBits       nS_SDU_ControlBits,              //V
OCT2                     bVCI,                            //V
octetstring              nS_SDU                           //V
// decoder interprets all octets after the 
// first 4 octets as NS SDU
}

type record PDU_SNS_Ack
{
OCT1                     nsPduType,
NSEI_NS                  nSEI_NS,                           //TLV
integer                  transactionID,                     //V
CauseNS                  causeNS             optional,      //TLV
IP_Address_NS            iP_Address_NS       optional,      //TV
ListofIP4Elements        listofIP4Elements   optional,      //TLV
ListofIP6Elements        listofIP6Elements   optional       //TLV
} with {
        variant (transactionID) "FIELDLENGTH(8)";
        variant "TAG (
                causeNS,                           iEI = '00'O;
                iP_Address_NS,                   iEI = '0B'O;
                listofIP4Elements,          iEI = '05'O;
                listofIP6Elements,          iEI = '06'O              
        )"
}

type record PDU_SNS_Add
{
OCT1                     nsPduType,
NSEI_NS                  nSEI_NS,                          //TLV
integer                  transactionID,                    //V
ListofIP4Elements        listofIP4Elements optional,       //TLV
ListofIP6Elements        listofIP6Elements optional        //TLV
} with {
        variant (transactionID) "FIELDLENGTH(8)";
        variant "TAG (
                listofIP4Elements,          iEI = '05'O;
                listofIP6Elements,          iEI = '06'O
         )"              
}

type record PDU_SNS_ChangeWeight
{
OCT1                     nsPduType,
NSEI_NS                  nSEI_NS,                         //TLV
integer                  transactionID,                   //V
ListofIP4Elements        listofIP4Elements optional,      //TLV
ListofIP6Elements        listofIP6Elements optional       //TLV
} with {
        variant (transactionID) "FIELDLENGTH(8)";
        variant "TAG (
                listofIP4Elements,          iEI = '05'O;
                listofIP6Elements,          iEI = '06'O
         )" 
}

type record PDU_SNS_Config
{
OCT1                     nsPduType,
EndFlag                  endFlag,                           //V
NSEI_NS                  nSEI_NS,                           //TLV
ListofIP4Elements        listofIP4Elements optional,        //TLV
ListofIP6Elements        listofIP6Elements optional         //TLV
} with { 
      variant "TAG (
                listofIP4Elements,          iEI = '05'O;
                listofIP6Elements,          iEI = '06'O
         )" 
}



type record PDU_SNS_Config_Ack
{
OCT1                     nsPduType,
NSEI_NS                  nSEI_NS,                               //TLV
CauseNS                  causeNS               optional         //TLV
} with { 
      variant "TAG (causeNS,                   iEI = '00'O;)"
}



type record PDU_SNS_Delete
{
OCT1                     nsPduType,
NSEI_NS                  nSEI_NS,                              //TLV
integer                  transactionID,                        //V
IP_Address_NS            iP_Address_NS         optional,       //TV
ListofIP4Elements        listofIP4Elements     optional,       //TLV
ListofIP6Elements        listofIP6Elements     optional        //TLV
} with {
        variant (transactionID) "FIELDLENGTH(8)";
        variant "TAG (
                iP_Address_NS,                        iEI = '0B'O;
                listofIP4Elements,                iEI = '05'O;
                listofIP6Elements,               iEI = '06'O
        )"
}

type record PDU_SNS_Size
{
OCT1                     nsPduType,
NSEI_NS                  nSEI_NS,                            //TLV
ResetFlag                resetFlag,                          //TV
MaxNumberOfNSVCs         maxNumberOfNSVCs,                   //TV
NumberOfIP_Endpoints     numberOfIP4_Endpoints    optional,  //TV
NumberOfIP_Endpoints     numberOfIP6_Endpoints    optional   //TV
} with { 
      variant "TAG (
                    numberOfIP4_Endpoints,                   iEI = '08'O;      
                    numberOfIP6_Endpoints,                   iEI = '09'O;
      )"  
}


type record PDU_SNS_Size_Ack
{
OCT1                     nsPduType,
NSEI_NS                  nSEI_NS,    
CauseNS                  causeNS             optional       //TLV
} with { 
      variant "TAG (causeNS,                   iEI = '00'O;)"
}



type union PDU_NS
{

PDU_NS_Alive                  pDU_NS_Alive,
PDU_NS_Alive_Ack              pDU_NS_Alive_Ack,
PDU_NS_Block                  pDU_NS_Block,
PDU_NS_Block_Ack              pDU_NS_Block_Ack,
PDU_NS_Reset                  pDU_NS_Reset,
PDU_NS_Reset_Ack              pDU_NS_Reset_Ack,
PDU_NS_Status                 pDU_NS_Status,
PDU_NS_Unblock                pDU_NS_Unblock,
PDU_NS_Unblock_Ack            pDU_NS_Unblock_Ack,
PDU_NS_Unitdata               pDU_NS_Unitdata,
PDU_SNS_Ack                   pDU_SNS_Ack,
PDU_SNS_Add                   pDU_SNS_Add,
PDU_SNS_ChangeWeight          pDU_SNS_ChangeWeight,
PDU_SNS_Config                pDU_SNS_Config,
PDU_SNS_Config_Ack            pDU_SNS_Config_Ack,
PDU_SNS_Delete                pDU_SNS_Delete,
PDU_SNS_Size                  pDU_SNS_Size,
PDU_SNS_Size_Ack              pDU_SNS_Size_Ack

} with { variant "TAG (              
                
                pDU_NS_Alive,           nsPduType ='0A'O;
                pDU_NS_Alive_Ack,       nsPduType ='0B'O;
                pDU_NS_Block,           nsPduType ='04'O;
                pDU_NS_Block_Ack,       nsPduType ='05'O;
                pDU_NS_Reset,           nsPduType ='02'O;
                pDU_NS_Reset_Ack,       nsPduType ='03'O;
                pDU_NS_Status,          nsPduType ='08'O;
                pDU_NS_Unblock,         nsPduType ='06'O;
                pDU_NS_Unblock_Ack,     nsPduType ='07'O;
                pDU_NS_Unitdata,        nsPduType ='00'O;
                pDU_SNS_Ack,            nsPduType ='0C'O;
                pDU_SNS_Add,            nsPduType ='0D'O;
                pDU_SNS_ChangeWeight,   nsPduType ='0E'O;
                pDU_SNS_Config,         nsPduType ='0F'O;
                pDU_SNS_Config_Ack,     nsPduType ='10'O;
                pDU_SNS_Delete,         nsPduType ='11'O;
                pDU_SNS_Size,           nsPduType ='12'O;
                pDU_SNS_Size_Ack,       nsPduType ='13'O

              )"
}


}with{ encode "RAW"} // end of module
