/******************************************************************************/
// @copyright   Copyright Notification
//   No part may be reproduced except as authorized by written permission.
//   The copyright and the foregoing restriction extend to reproduction in all media.
//   Trademark 2010, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC).
//   All rights reserved.
// @version: IWD_10wk37
// $Date: 2010-09-15 18:29:22 +0200 (Wed, 15 Sep 2010) $
// $Rev: 3910 $
/******************************************************************************/
module DRB_12 {
//=========================================================================
// Import Part
//=========================================================================

  import from CommonDefs all;
  import from EUTRA_CommonProcedures all;
  import from EUTRA_LoopBack all;
  import from EPS_NAS_Templates all;
  import from EPS_NAS_Constants all;
  import from EUTRA_ASP_TypeDefs all;
  import from EUTRA_AspCommon_Templates all;
  import from EUTRA_CommonDefs all;
  import from EUTRA_RRC_ASN1_Definitions language "ASN.1:1997" all;
  import from EUTRA_ASP_DrbDefs all;
  import from EUTRA_DRB_Templates all;
  import from EUTRA_Component all;
  import from EUTRA_RRCSteps all;
  import from L2_CommonTemplates all;
  import from L2_CommonFunctions all;
  import from EUTRA_ConfigurationSteps all;
  import from EUTRA_CellInfo all;
  import from EUTRA_Timing all;
  import from EUTRA_NASSteps all;
  import from EUTRA_LoopBack_TypeDefs all;
  // following imports added for adhoc solution for week 37
  import from EUTRA_Paging all;
  import from EPS_NAS_TypeDefs all;
  import from EPS_NAS_MsgContainers all;
  import from EUTRA_RRC_Templates all;

  //=========================================================================
  // Test case main functions
  //=========================================================================

  group LocalFunctions {
  
  //----------------------------------------------------------------------------
  /*
   * @desc      release all DRBs except DRB1
   * @param     p_CellId
   * @param     p_NoOfAddDRBs_AM
   * @param     p_NoOfAddDRBs_UM
   * @status    APPROVED
   */
  function f_EUTRA_SS_DRB_Release_NoDRB1 (CellId_Type p_CellId,
                                          integer p_NoOfAddDRBs_AM,
                                          integer p_NoOfAddDRBs_UM) runs on EUTRA_PTC
  {
    var template (value) RadioBearerList_Type v_DrbList;
    var integer n;
    if ((p_NoOfAddDRBs_AM+p_NoOfAddDRBs_UM)>1) // release if more than one DRB's exist
    //@sic R5s100385
    {
        for (n:=1; n<(p_NoOfAddDRBs_AM+p_NoOfAddDRBs_UM); n:= n+1)
        {
            v_DrbList[n-1] := cs_DRB_Release(tsc_DRB1+n);
        };
    
        f_EUTRA_SS_CommonRadioBearerConfig(p_CellId, v_DrbList);
    }
    // IF only one DRB was configured do nothing
  }
  
  //----------------------------------------------------------------------------
  /*
   * @desc      initialise the BSR values to be expected for PDCP PDU sizes considering each PDCP SDU = 40 bytes
   *            As per 36.321 clause RLC and MAC PDU Headers are not considered in BSR transmission
   * @param     p_NoOfAddDRBs
   * @return    integer
   * @status    APPROVED
   */
  function fl_MinBSRValueSet (integer p_NoOfAddDRBs) return integer
  {
    var integer v_MinBSR_Size := 0;

    select (p_NoOfAddDRBs) {
      case (1) {
        // PDCP Size of 40 bytes;
        v_MinBSR_Size := 10 ; //10   36 < BS <= 42
      }
      case (2) {
        // PDCP Size of 80 bytes;
        v_MinBSR_Size := 15 ; //15   78 < BS <= 91
      }
      case (3) {
        // PDCP Size of 120 bytes;
        v_MinBSR_Size := 17 ; //17   107 < BS <= 125
      }
      case (4) {
        // PDCP Size of 160 bytes;
        v_MinBSR_Size := 19 ; //19   146 < BS <= 171
      }
      case (5) {
        // PDCP Size of 200 bytes;
        v_MinBSR_Size := 20 ; //20   171 < BS <= 200
      }
      case (6) {
        // PDCP Size of 240 bytes;
        v_MinBSR_Size := 22 ; //22   234 < BS <= 274
      }
      case else { // 7 and 8
        // PDCP Size of 280/320  bytes;
        v_MinBSR_Size := 23 ; //23   274 < BS <= 321
      }
    }  // end of select
    return v_MinBSR_Size;
  };
  
  //----------------------------------------------------------------------------
  /*
   * @desc      Generic function to allow any combinition of AM and UM bearers;
   *            SRBs and DRBs are expected to be established at the SS beforehand
   * @param     p_CellId
   * @param     p_UE_TestLoopModeA_LB_Setup
   * @param     p_NoOfAddDRBs_AM
   * @param     p_NoOfAddDRBs_UM
   * @param     p_QoS
   * @param     p_Tft
   * @param     p_DRB_ToAddModList  (default value: omit)
   * @status    APPROVED
   */
  function f_EUTRA_LoopBackActivation_State4_12_2(CellId_Type p_CellId,
                                                  template (value) UE_TestLoopModeA_LB_Setup_Type p_UE_TestLoopModeA_LB_Setup,
                                                  integer p_NoOfAddDRBs_AM,
                                                  integer p_NoOfAddDRBs_UM,
                                                  template (omit) EPS_QoSList_Type p_QoS,
                                                  template (omit) Tft_List_Type p_Tft,
                                                  template (omit) DRB_ToAddModList p_DRB_ToAddModList := omit) runs on EUTRA_PTC
  {
    var template (omit) DRB_ToAddModList v_DRB_ToAddModList := p_DRB_ToAddModList;                // => apply default setiing acc. 36.508 cl. 4.8.2.1.7 */
    var template (omit) MAC_MainConfig_Type v_MAC_MainConfig := omit;               // => apply default setting acc. 36.508 cl. 4.8.2.1.5 */
    var template (omit) PhysicalConfigDedicated v_PhysicalConfigDedicated := omit;  // => apply default setting acc. 36.508 cl. 4.8.2.1.6 */
    f_EUTRA_GenericRbEst_Common_Adhoc(p_CellId, //@sic R5s100293 sic@
                                               // after week 37 delivery _Adhoc to be removed
                                p_NoOfAddDRBs_AM,
                                p_NoOfAddDRBs_UM,
                                v_DRB_ToAddModList,
                                v_MAC_MainConfig,
                                v_PhysicalConfigDedicated,
                                p_QoS,
                                p_Tft);   // bring UE to State 3
    f_EUTRA_CloseUE_TestLoopModeA(p_CellId, p_UE_TestLoopModeA_LB_Setup);             // Step 1-2
  };
  group AdhocSolution {
      //This group is created only for week 37 deliver; @sic R5s100293 sic@
      // will be removed after week 37 delivery when SS support for DRX is available

   function f_EUTRA_GenericRbEst_Common_Adhoc ( CellId_Type p_CellId,
                                         integer p_NoOfAddDRBs_AM,
                                         integer p_NoOfAddDRBs_UM,
                                         template (omit) DRB_ToAddModList p_DRB_ToAddModList,
                                         template (omit) MAC_MainConfig_Type p_MAC_MainConfig,
                                         template (omit) PhysicalConfigDedicated p_PhysicalConfigDedicated,
                                         template (omit) EPS_QoSList_Type p_QoS,
                                         template (omit) Tft_List_Type p_Tft,
                                         boolean p_PDCP_StatusReportRequired := true )
    runs on EUTRA_PTC
  {
    var GutiParameters_Type v_GutiParameters := f_EUTRA_CellInfo_GetGuti ( p_CellId );

    /* Step 2 */
    f_EUTRA_UE_Page ( p_CellId,
                      cs_NasPaging_OneRecord ( cs_PagingUE_Identity_S_TMSI ( v_GutiParameters.MME_Code, v_GutiParameters.M_TMSI )) ); //@sic R5s100398 sic@
    
    // Steps 3 - 10
    f_EUTRA_ServiceRequestAndActivate_SRB2_DRB_Adhoc ( p_CellId,
                                                 p_NoOfAddDRBs_AM,
                                                 p_NoOfAddDRBs_UM,
                                                 p_DRB_ToAddModList,
                                                 p_MAC_MainConfig,
                                                 p_PhysicalConfigDedicated,
                                                 p_QoS,
                                                 p_Tft,
                                                 p_PDCP_StatusReportRequired);
  }
  function f_EUTRA_ServiceRequestAndActivate_SRB2_DRB_Adhoc(CellId_Type p_CellId,
                                                      UInt_Type p_NoOfAddDRBs_AM,
                                                      UInt_Type p_NoOfAddDRBs_UM,
                                                      template (omit) DRB_ToAddModList p_DRB_ToAddModList,
                                                      template (omit) MAC_MainConfig_Type p_MAC_MainConfig,
                                                      template (omit) PhysicalConfigDedicated p_PhysicalConfigDedicated,
                                                      template (omit) EPS_QoSList_Type p_QoS,
                                                      template (omit) Tft_List_Type p_Tft,
                                                      boolean p_PDCP_StatusReportRequired := true) runs on EUTRA_PTC
  {
    var RRC_TransactionIdentifier v_RRC_TI := tsc_RRC_TI_Def;
    var NAS_MSG_Indication_Type v_NAS_Ind;
    var NAS_KsiValue v_KsiValue;

    // =====================================================
    // step 3-10 of procedure in 36.508 cl. 4.5.3.3

    // Step 3 - 5 of Generic RB establishment procedure
    //Check the Service Request message
    v_KsiValue := f_EUTRA_SecurityKSIasme_Get ( );
    v_NAS_Ind := f_EUTRA_RRC_ConnEst_DefWithNas ( p_CellId,
                                                  v_RRC_TI,
                                                  cr_EstablishmentCause_mt_Access,
                                                  cr_NAS_Indication(tsc_SHT_IntegrityProtected,
                                                  cr_508_SERVICE_REQUEST ( v_KsiValue )));
     if (  p_NoOfAddDRBs_UM > 0) // DRX short is used
     {
         f_EUTRA_PeriodicULGrantTransmission(eutra_Cell1,
                                        cs_TimingInfo_Now ,// immediate effect
                                        12, // Imcs => Mod =16QAM Arbitrarily selected forTBS =776
                                        4, // Nprb
                                        60);  // period =60 =>  less than DRX inactivity timer [100 ms]
                                              // and less than time needed for SR to be transmitted DSR transmax
     };
    /* Step 6 - 8 */
    f_EUTRA_Activate_SRB2_DRB_SendRrcMsg ( p_CellId,
                                           v_RRC_TI,
                                           v_NAS_Ind.SecurityProtection.NasCount,
                                           p_NoOfAddDRBs_AM,
                                           p_NoOfAddDRBs_UM,
                                           p_DRB_ToAddModList,
                                           p_MAC_MainConfig,
                                           p_PhysicalConfigDedicated,
                                           p_QoS,
                                           p_Tft,
                                           p_PDCP_StatusReportRequired);      /* @sic R5s100315 sic@ */
    
    /* Step 9 - 10 */
    f_EUTRA_Activate_SRB2_DRB_ReceiveRrcAndNasMsg(p_CellId,
                                                  v_RRC_TI,
                                                  p_NoOfAddDRBs_AM,
                                                  p_NoOfAddDRBs_UM);          /* @sic R5s100315 sic@ */
  }
  } // end of group adhoc

  /*
   * @desc      generic configuration for multiple DRBs;
   *            configures additional DRBs; it is assumed that DRB1 is reverved for the default bearer which is already configured
   * @param     p_CellId
   * @param     p_NoOfAddDRBs_AM
   * @param     p_NoOfAddDRBs_UM
   * @status    APPROVED
   */
  function f_EUTRA_SS_DRB_AddConfig_1211 ( CellId_Type  p_CellId,
                                           integer p_NoOfAddDRBs_AM,
                                           integer p_NoOfAddDRBs_UM) runs on EUTRA_PTC
  {
    var template (value) RadioBearerList_Type v_DRB_ToAddModList;
    var integer v_DRB_Id;
    var integer n, m;

    if (p_NoOfAddDRBs_AM + p_NoOfAddDRBs_UM > 0) {          // @sic R5s100100 sic@
      v_DRB_Id := tsc_DRB1 + 1;                             // DRB1 is the default bearer
      for (n := 0; n < p_NoOfAddDRBs_AM; n := n + 1) {
        v_DRB_ToAddModList[n] := cs_OneDRB_ConfigUM(v_DRB_Id, -, cs_RLC_Configuration_AM(cds_TX_AM_RLC_t_PollRetransmit(ms250)));//@sic R5s100469 sic@
        v_DRB_Id := v_DRB_Id + 1;
      }
      for (m := 0; m < p_NoOfAddDRBs_UM; m := m + 1) {
        v_DRB_ToAddModList[n+m] := cs_OneDRB_ConfigUM(v_DRB_Id, cds_DRB_PDCP_Conf_UM_ModifyDiscardTime(ms300));
        v_DRB_Id := v_DRB_Id + 1;
      }
      
      f_EUTRA_SS_CommonRadioBearerConfig(p_CellId, v_DRB_ToAddModList);
    }
  };
  
  //----------------------------------------------------------------------------
  /*
   * @desc      generic procedure for DRB test cases acc. to 36.523-1 cl. 12.1.1
   * @param     p_CellId
   * @param     p_NoOfAddDRBs_AM
   * @param     p_NoOfAddDRBs_UM
   * @status    APPROVED
   */
  function f_GenericProcedure_12_1_1 (CellId_Type p_CellId,
                                      integer p_NoOfAddDRBs_AM,
                                      integer p_NoOfAddDRBs_UM ) runs on EUTRA_PTC
  { //@sic R5s100100
    const integer tsc_UM_PDCP_SDU_Size := 40; // Bytes
    const integer tsc_AM_PDCP_SDU_Size := 40; // Bytes

    var SubFrameTiming_Type v_TimingInfo;
    var integer n, m,v_DRB_Id;
    var PDCP_SDU_Type v_DRB_DataList[8];
    var boolean v_DRB_Flag[8] :={false, false, false, false, false, false, false, false};
    var integer v_MinBSR_AM_Size := fl_MinBSRValueSet(p_NoOfAddDRBs_AM); // As per 36.508 Table 4.8.2.1.4-1 all AM DRB's are mapped to LCG =1
    var integer v_MinBSR_UM_Size := fl_MinBSRValueSet(p_NoOfAddDRBs_UM); // As per 36.508 Table 4.8.2.1.4-1 all UM DRB's are mapped to LCG =2
    var template (value) Tft_List_Type v_Tft_List;
    var template (value) EPS_QoSList_Type v_QoSList;
    
    var template (omit) DRB_ToAddModList v_DRB_ToAddModList;
    timer t_Watchdog := 5.0;

    // SS configuration for approprite DRB's
    f_EUTRA_SS_DRB_AddConfig_1211(p_CellId, p_NoOfAddDRBs_AM-1, p_NoOfAddDRBs_UM);
    // Generate TFTFilters and QOS
    for (n := 0; n < (p_NoOfAddDRBs_AM-1 + p_NoOfAddDRBs_UM); n := n + 1)
      {
        v_QoSList[n] := cs_508_EPS_QoS_Dedicated_1;
        select (n) {
          case (0) {
            v_Tft_List[n] := cs_508_Tft_Dedicated_1(tsc_EpsDedicatedBearerId);
          }
          case (1) {
            v_Tft_List[n] := cs_508_Tft_Dedicated_1(tsc_EpsDedicatedBearerId2);
          }
        //@sic R5s100116
        case (2) {
            v_Tft_List[n] := cs_508_Tft_Dedicated_1(tsc_EpsDedicatedBearerId3);
          }
          case (3) {
            v_Tft_List[n] := cs_508_Tft_Dedicated_1(tsc_EpsDedicatedBearerId4);
          }
          case (4) {
            v_Tft_List[n] := cs_508_Tft_Dedicated_1(tsc_EpsDedicatedBearerId5);
          }
          case (5) {
            v_Tft_List[n] := cs_508_Tft_Dedicated_1(tsc_EpsDedicatedBearerId6);
          }
          case (6) {
            v_Tft_List[n] := cs_508_Tft_Dedicated_1(tsc_EpsDedicatedBearerId7);
          }
          case else {
            FatalError(__FILE__, __LINE__, "not supported total number of bearers");
            /// dummy statement added for satisfying the compiler
          }
        } // end of select
      }// end of for
      // Generate DRB List;

      v_DRB_Id := tsc_DRB1;                             // default bearer
      for (n := 0; n < (p_NoOfAddDRBs_AM ); n := n + 1) {                // default bearer included in the list (=> p_NoOfAddDRBs_AM + 1)
        
        v_DRB_ToAddModList[n] := cs_508_DRB_ToAddMod_Common(v_DRB_Id,
                                                            cds_PDCP_Config_DRB_AM_NoPDCP_StatusReport, //@sic R5s100469 sic@
                                                            cs_508_RLC_Config_DRB_AM(cds_TX_AM_RLC_t_PollRetransmit(ms250)), //@sic R5s100469 sic@
                                                            cs_508_LogicalChannelConfig_DRB_AM);
        
        v_DRB_Id := v_DRB_Id + 1;
      }
      
      for (m := 0; m < p_NoOfAddDRBs_UM; m := m + 1) {
        v_DRB_ToAddModList[p_NoOfAddDRBs_AM + m] := cs_508_DRB_ToAddMod_UM_DiscardTimer_300ms (v_DRB_Id);
        v_DRB_Id := v_DRB_Id + 1;
      }
    
    // Num AM bearers 1 less as Default bearer is not included which is configured by default.
    f_EUTRA_LoopBackActivation_State4_12_2(p_CellId, cs_UE_TestLoopModeA_LB_Setup_NoScaling, p_NoOfAddDRBs_AM-1, p_NoOfAddDRBs_UM, v_QoSList, v_Tft_List,v_DRB_ToAddModList);
    // go to sate 4 with desired number of AM and UM DRB's established
    // initialise PDCP SDU's to be sent on DRB's
    for (n := 0; n < (p_NoOfAddDRBs_AM ); n := n + 1) {                // default bearer included in the list
      v_DRB_DataList[n] := f_GetN_OctetsFromPRBS(n*100, tsc_AM_PDCP_SDU_Size);
    }
    for (m := 0; m < p_NoOfAddDRBs_UM; m := m + 1) {
      v_DRB_DataList[n+m] := f_GetN_OctetsFromPRBS((n+m)*100, tsc_UM_PDCP_SDU_Size);
    }
    // step 1
    //@sic  R5s100293 sic@
    // remove if conditional statement after week 37 delivery Need prose CR for validation
    if (p_NoOfAddDRBs_UM ==0)
    {
    f_EUTRA_StopULGrantTransmission_PUCCH_Sync(p_CellId, cs_TimingInfo_Now);
    }
    // start report of BSR
    f_SS_ConfigBufferStatusReportIndMode(p_CellId, tsc_L1Mac_IndicationMode_Enable);
    
    // step 2

    v_TimingInfo := f_EUTRA_GetNextSendOccasion (p_CellId, 200); // app 200 ms in future

    for (n := 0; n < (p_NoOfAddDRBs_AM+ p_NoOfAddDRBs_UM ); n := n + 1)
      {
        DRB.send (cas_DRB_COMMON_REQ_PDCP_SDU(p_CellId,
                                              {Drb:= n+1},
                                              cs_TimingInfo(v_TimingInfo.SFN.Number, v_TimingInfo.Subframe.Number ),
                                              cs_PDCP_SDUList_1 (v_DRB_DataList[n])));
        v_DRB_Flag[n] := true; // Expect a loop back Data for the DRB
      };
    // step 2a
    // UL Grant of 32 bits Nprb =1, Imcs=Itbs=2
    //@sic  R5s100293 sic@
    // remove if conditional statement after week 37 delivery Need prose CR for validation only true branch will exist
    if (p_NoOfAddDRBs_UM ==0)
    {
        f_EUTRA_StartExplicitULGrantTransmissionOnSR_Reception(p_CellId, cs_TimingInfo_Now, 2, 1);
    } else
    {

         f_EUTRA_PeriodicULGrantTransmission(eutra_Cell1,
                                        cs_TimingInfo_Now ,// immediate effect
                                        2,
                                        1,
                                        60);  // period =60 =>  less than DRX inactivity timer [100 ms]
                                              // and less than time needed for SR to be transmitted DSR transmax

    }


    
    // step 3
    t_Watchdog.start;
    // the BSR here is considered to be Regular BSR not Padding  BSR, hence when data on only one LCG is available
    // i.e. (p_NoOfAddDRBs_UM==0), a short BSR with 2 byte padding is reported.
    alt {
      [(p_NoOfAddDRBs_UM==0)] SYSIND.receive(car_BSR_IND(eutra_Cell1, cr_TimingInfo_Any, cr_ShortBSR_Ind(2, (v_MinBSR_AM_Size..63))))
        {
          t_Watchdog.stop;
        }
      [] SYSIND.receive(car_BSR_IND(eutra_Cell1, cr_TimingInfo_Any, cr_LongBSR_Ind(0, (v_MinBSR_UM_Size..63), (v_MinBSR_AM_Size..63),0)))
        {
          t_Watchdog.stop;
        }
      [] SYSIND.receive (car_BSR_IND(eutra_Cell1, cr_TimingInfo_Any, ?))
        {
          repeat;
        }
    };
    // stop report of BSR
    f_SS_ConfigBufferStatusReportIndMode(p_CellId, tsc_L1Mac_IndicationMode_Disable);
    
    // 4 preconfig SS for UL grant in an
    v_TimingInfo := f_EUTRA_GetCurrentTiming(p_CellId);
    v_TimingInfo.SFN.Number := (v_TimingInfo.SFN.Number + 10) mod 1024;
    // app 100 ms in future
    v_TimingInfo.Subframe.Number := 4;
    // selected for default TDD configurations and FDD results in UL data transmission in Sub frame 8
    // UL Grant 40B PDCP SDU + 2B PDCP H+ 2B RLC Header + 2 B MAC Header = 46 B
    // MAX 8 Data PDU's => 8 * 46 = 368 B
    // Any status PDU's 2 B RLC PDU+ 2B MAC H = 4 B
    // MAX 8 Status PDU's => 8 * 4 = 32 B
    // Total MAx = 400 B = 3200 b
    // TBS of 3880 selected to further provide buffer for RLC Status PDU's if Any;
    // Nprb = 15 ITbs = 13 => Imcs =14
    f_EUTRA_OneULGrantTransmission(p_CellId, cs_TimingInfo(v_TimingInfo.SFN.Number, v_TimingInfo.Subframe.Number), 14, 15 );
    //If conditional statement only for week 37, will be reomved later only true branch will exist
    //@sic  R5s100293 sic@
    if (p_NoOfAddDRBs_UM !=0)
    {
         v_TimingInfo := f_EUTRA_TimingInfoAdd (v_TimingInfo, 60); // 60 ms< 100 ms DRX inactivity timer
         f_EUTRA_PeriodicULGrantTransmission(eutra_Cell1,
                                        cs_TimingInfo_Now ,// immediate effect
                                        2,
                                        1,
                                        60);  // period =60 =>  less than DRX inactivity timer [100 ms]
                                              // and less than time needed for SR to be transmitted DSR transmax

    }
    v_TimingInfo.Subframe.Number := 8;
    // expected SFN of UL Data
    // Step 5
    t_Watchdog.start;
    alt {
      [v_DRB_Flag[0]] DRB.receive(car_DRB_COMMON_IND_PDCP_SDUList (p_CellId,tsc_RbId_DRB1,
                                                                   cr_TimingInfo(v_TimingInfo.SFN.Number, v_TimingInfo.Subframe.Number),
                                                                   cr_PDCP_SDUList_1(v_DRB_DataList[0])))
        {
          v_DRB_Flag[0] := false;
          repeat;
          
        };
      [v_DRB_Flag[1]] DRB.receive(car_DRB_COMMON_IND_PDCP_SDUList (p_CellId,tsc_RbId_DRB2,
                                                                   cr_TimingInfo(v_TimingInfo.SFN.Number, v_TimingInfo.Subframe.Number),
                                                                   cr_PDCP_SDUList_1(v_DRB_DataList[1])))
        {
          v_DRB_Flag[1] := false;
          repeat;
        };
      [v_DRB_Flag[2]] DRB.receive(car_DRB_COMMON_IND_PDCP_SDUList (p_CellId,tsc_RbId_DRB3,
                                                                   cr_TimingInfo(v_TimingInfo.SFN.Number, v_TimingInfo.Subframe.Number),
                                                                   cr_PDCP_SDUList_1(v_DRB_DataList[2])))
        {
          v_DRB_Flag[2] := false;
          repeat;
        };
      [v_DRB_Flag[3]] DRB.receive(car_DRB_COMMON_IND_PDCP_SDUList (p_CellId,tsc_RbId_DRB4,
                                                                   cr_TimingInfo(v_TimingInfo.SFN.Number, v_TimingInfo.Subframe.Number),
                                                                   cr_PDCP_SDUList_1(v_DRB_DataList[3])))
        {
          v_DRB_Flag[3] := false;
          repeat;
        };
      [v_DRB_Flag[4]] DRB.receive(car_DRB_COMMON_IND_PDCP_SDUList (p_CellId,tsc_RbId_DRB5,
                                                                   cr_TimingInfo(v_TimingInfo.SFN.Number, v_TimingInfo.Subframe.Number),
                                                                   cr_PDCP_SDUList_1(v_DRB_DataList[4])))
        {
          v_DRB_Flag[4] := false;
          repeat;
        };
      [v_DRB_Flag[5]] DRB.receive(car_DRB_COMMON_IND_PDCP_SDUList (p_CellId,tsc_RbId_DRB6,
                                                                   cr_TimingInfo(v_TimingInfo.SFN.Number, v_TimingInfo.Subframe.Number),
                                                                   cr_PDCP_SDUList_1(v_DRB_DataList[5])))
        {
          v_DRB_Flag[5] := false;
          repeat;
        };
      [v_DRB_Flag[6]] DRB.receive(car_DRB_COMMON_IND_PDCP_SDUList (p_CellId,tsc_RbId_DRB7,
                                                                   cr_TimingInfo(v_TimingInfo.SFN.Number, v_TimingInfo.Subframe.Number),
                                                                   cr_PDCP_SDUList_1(v_DRB_DataList[6])))
        {
          v_DRB_Flag[6] :=false;
          repeat;
        };
      [v_DRB_Flag[7]] DRB.receive(car_DRB_COMMON_IND_PDCP_SDUList (p_CellId,tsc_RbId_DRB8,
                                                                   cr_TimingInfo(v_TimingInfo.SFN.Number, v_TimingInfo.Subframe.Number),
                                                                   cr_PDCP_SDUList_1(v_DRB_DataList[7])))
        {
          v_DRB_Flag[7] := false;
          repeat;
        };
      [] t_Watchdog.timeout
        {
          if ( v_DRB_Flag[0] or v_DRB_Flag[1] or v_DRB_Flag[2] or v_DRB_Flag[3] or
               v_DRB_Flag[4] or v_DRB_Flag[5] or v_DRB_Flag[6] or v_DRB_Flag[7])
            {
              f_EUTRA_SetVerdictFailOrInconc(__FILE__, __LINE__, "UE is not looping back data on some or all DRB's");
            }
          else
            {
              f_EUTRA_PreliminaryPass (__FILE__, __LINE__, "UE has looped back data on all DRB's in one TTI");
            };
        };
    };
    // configure SS in normal grant transmission
    //If conditional statement only for week 37, will be reomved later only true branch will exist
    //@sic  R5s100293 sic@
    if (p_NoOfAddDRBs_UM ==0)
    {
        f_EUTRA_StartDefULGrantTransmission(eutra_Cell1, cs_TimingInfo_Now);
    } else
    {
        f_EUTRA_PeriodicULGrantTransmission(eutra_Cell1,
                                        cs_TimingInfo_Now ,// immediate effect
                                        12, // Imcs => Mod =16QAM Arbitrarily selected forTBS =776
                                        4, // Nprb
                                        60);  // period =60 =>  less than DRX inactivity timer [100 ms]
                                              // and less than time needed for SR to be transmitted DSR transmax
     };
    // step 6
    f_EUTRA_RRC_ConnectionRelease(p_CellId, tsc_RRC_TI_Def, other);
    // Note the f_EUTRA_RRC_ConnectionRelease reconfig's on SS side DRB1; other additional DRB's needs to be released and will
    // be configured in new sub test;
    f_EUTRA_SS_DRB_Release_NoDRB1(p_CellId, p_NoOfAddDRBs_AM, p_NoOfAddDRBs_UM);
  };

  
 
  /* function f_12_2_GenericProcedure_Applicability (integer p_NoOfAddDRBs_AM,
                                                   integer p_NoOfAddDRBs_UM) return boolean {
    var boolean v_Bol := false;

    // Ref 36.331 Appendix B.1
   // - RB combination 1: SRB1 and SRB2 for DCCH + 1x AM DRB
   // - RB combination 2: SRB1 and SRB2 for DCCH + 1x AM DRB + 1x UM DRB
    //- RB combination 3: SRB1 and SRB2 for DCCH + 2x AM DRB
    //- RB combination 4: SRB1 and SRB2 for DCCH + 2x AM DRB + 1x UM DRB
    //- RB combination 5: SRB1 and SRB2 for DCCH + 2x AM DRB + 2x UM DRB
    //- RB combination 6: SRB1 and SRB2 for DCCH + 3x AM DRB
    //- RB combination 7: SRB1 and SRB2 for DCCH + 3x AM DRB + 1x UM DRB
   // - RB combination 8: SRB1 and SRB2 for DCCH + 3x AM DRB + 2x UM DRB
    //- RB combination 9: SRB1 and SRB2 for DCCH + 4x AM DRB
    //- RB combination 10: SRB1 and SRB2 for DCCH + 4x AM DRB + 1x UM DRB
   // - RB combination 11: SRB1 and SRB2 for DCCH + 4x AM DRB + 2x UM DRB
   // - RB combination 12: SRB1 and SRB2 for DCCH + 5x AM DRB + 3x UM DRB
   // - RB combination 13: SRB1 and SRB2 for DCCH + 8x AM DRB

    if ((pc_FeatrGrp_20 == false) and (pc_FeatrGrp_7 == false ))
    // support RB combinations 1, 3, 6 and 9
    {
        if ( (p_NoOfAddDRBs_UM ==0) and
             ( (p_NoOfAddDRBs_AM== 1) or (p_NoOfAddDRBs_AM== 2) or (p_NoOfAddDRBs_AM== 3) or (p_NoOfAddDRBs_AM== 4)))
             {
                 v_Bol := true; // combination applied
             };

    }
    else if ((pc_FeatrGrp_20 == false) and (pc_FeatrGrp_7 == true ))
    //support RB combinations 1, 2, 3, 4, 6, 7, 9 and 10
    {
        if ( (p_NoOfAddDRBs_UM ==0) and
             ( (p_NoOfAddDRBs_AM== 1) or (p_NoOfAddDRBs_AM== 2) or (p_NoOfAddDRBs_AM== 3) or (p_NoOfAddDRBs_AM== 4)))
             // 1,3,6,9
             {
                 v_Bol := true; // combination applied
             }
         else if ( (p_NoOfAddDRBs_UM ==1) and
                   ((p_NoOfAddDRBs_AM== 1)or (p_NoOfAddDRBs_AM== 2)or (p_NoOfAddDRBs_AM== 3) or (p_NoOfAddDRBs_AM== 4)))
              //2, 4, 7 & 10
              {
                 v_Bol := true; // combination applied
             };

    }
    else if ((pc_FeatrGrp_20 == true) and (pc_FeatrGrp_7 == false ))
    //support RB combinations 1, 3, 6, 9 and 13
    {
        if ( (p_NoOfAddDRBs_UM ==0) and
             ( (p_NoOfAddDRBs_AM== 1) or (p_NoOfAddDRBs_AM== 2) or (p_NoOfAddDRBs_AM== 3) or (p_NoOfAddDRBs_AM== 4) or (p_NoOfAddDRBs_AM== 8)))
             {
                 v_Bol := true; // combination applied
             };
    }
    else
    // Both FGI 7 and 20 are true
    //support RB combinations 1 to 13
    {
        if ( (p_NoOfAddDRBs_UM ==0) and
             ( (p_NoOfAddDRBs_AM== 1) or (p_NoOfAddDRBs_AM== 2) or (p_NoOfAddDRBs_AM== 3) or (p_NoOfAddDRBs_AM== 4)or (p_NoOfAddDRBs_AM== 8)))
             // 1,3,6,9, 13
             {
                 v_Bol := true; // combination applied
             }
         else if ( (p_NoOfAddDRBs_UM ==1) and
                   ((p_NoOfAddDRBs_AM== 1)or (p_NoOfAddDRBs_AM== 2)or (p_NoOfAddDRBs_AM== 3) or (p_NoOfAddDRBs_AM== 4)))
              //2, 4, 7 & 10
              {
                 v_Bol := true; // combination applied
             }
         else if ( (p_NoOfAddDRBs_UM ==2) and
                   ( (p_NoOfAddDRBs_AM== 2)or (p_NoOfAddDRBs_AM== 3) or (p_NoOfAddDRBs_AM== 4)))
              //5, 8 & 11
              {
                 v_Bol := true; // combination applied
             }
         else if ( (p_NoOfAddDRBs_UM ==3) and
                   (p_NoOfAddDRBs_AM== 5) )
                   // 12
               {
                 v_Bol := true; // combination applied
             };
    }
    return v_Bol;
    } */

}; //End of group LocalFunctions


  // Functions for Test cases
  //==========================================================
  // DRB/12.2.X MIMO not configured
  //==========================================================
  
  /*
   * @desc      REFERENCE TS 36.523-1 clause 12.2.1
   * @status    APPROVED
   */
  function f_TC_12_2_1_EUTRA ( ) runs on EUTRA_PTC
  { /* DRB/12.2
     * 12.2.1 : Data transfer of E-UTRA radio bearer combinations 1, 3, 6 and 9
     */
    
    ///////////////////////////////////////////////////////////////////////////////////
    //      PREAMBLE
    //////////////////////////////////////////////////////////////////////////////////
    f_EUTRA_Init (c1);
    f_EUTRA_CellConfig_Def (eutra_Cell1);
    f_EUTRA_Preamble (eutra_Cell1, STATE2A_TESTLOOP_ModeA);
    // Bring UE to state 3
    ///////////////////////////////////////////////////////////////////////////////////
    //      Test Body
    //////////////////////////////////////////////////////////////////////////////////
    f_EUTRA_TestBody_Set(true);
    // Test body starts
    // E-UTRA radio bearer combination 1: SRB1 and SRB2 for DCCH + 1xAM DRB
    f_GenericProcedure_12_1_1(eutra_Cell1, 1, 0);
    // E-UTRA radio bearer combination 3: SRB1 and SRB2 for DCCH + 2xAM DRB
    f_GenericProcedure_12_1_1(eutra_Cell1, 2, 0);
    // E-UTRA radio bearer combination 6: SRB1 and SRB2 for DCCH + 3xAM DRB
    f_GenericProcedure_12_1_1(eutra_Cell1, 3, 0);
    // E-UTRA radio bearer combination 9: SRB1 and SRB2 for DCCH + 4xAM DRB
    f_GenericProcedure_12_1_1(eutra_Cell1, 4, 0);
    f_EUTRA_TestBody_Set(false);
    //test body ends
    ///////////////////////////////////////////////////////////////////////////////////
    //      Post Amble
    //////////////////////////////////////////////////////////////////////////////////
    
    //Switch off UE and expect a DETACH REQUEST message
    f_EUTRA_Postamble (eutra_Cell1, E1_IDLE); //@sic R5s100279
  };
  
  /*
   * @desc      REFERENCE TS 36.523-1 clause 12.2.2
   * @status    (APPROVED)
   */
  function f_TC_12_2_2_EUTRA ( ) runs on EUTRA_PTC
  { /* DRB/12.2
     * 12.2.2 : Data transfer of E-UTRA radio bearer combinations 2,4,7 and 10
     */
    
    ///////////////////////////////////////////////////////////////////////////////////
    //      PREAMBLE
    //////////////////////////////////////////////////////////////////////////////////
    f_EUTRA_Init (c1);
    f_EUTRA_CellConfig_Def (eutra_Cell1);
    f_EUTRA_Preamble (eutra_Cell1, STATE2A_TESTLOOP_ModeA);
    // Bring UE to state 3
    ///////////////////////////////////////////////////////////////////////////////////
    //      Test Body
    //////////////////////////////////////////////////////////////////////////////////
    f_EUTRA_TestBody_Set(true);
    // Test body starts
    // E-UTRA radio bearer combination 2: SRB1 and SRB2 for DCCH + 1xAM DRB + 1xUM DRB
    f_GenericProcedure_12_1_1(eutra_Cell1, 1, 1);
    // E-UTRA radio bearer combination 4: SRB1 and SRB2 for DCCH + 2xAM DRB + 1xUM DRB
    f_GenericProcedure_12_1_1(eutra_Cell1, 2, 1);
    // E-UTRA radio bearer combination 7: SRB1 and SRB2 for DCCH + 3xAM DRB + 1xUM DRB
    f_GenericProcedure_12_1_1(eutra_Cell1, 3, 1);
    // E-UTRA radio bearer combination 10: SRB1 and SRB2 for DCCH + 4xAM DRB + 1xUM DRB
    f_GenericProcedure_12_1_1(eutra_Cell1, 4, 1);
    f_EUTRA_TestBody_Set(false);
    //test body ends
    ///////////////////////////////////////////////////////////////////////////////////
    //      Post Amble
    //////////////////////////////////////////////////////////////////////////////////
    
    //Switch off UE and expect a DETACH REQUEST message
    f_EUTRA_Postamble (eutra_Cell1, E1_IDLE);
  };
  
  function f_TC_12_2_3_EUTRA ( ) runs on EUTRA_PTC
  { /* DRB/12.2
       12.2.3 : Data transfer of E-UTRA radio bearer combinations 5,8,11 and 12
    */
    
    ///////////////////////////////////////////////////////////////////////////////////
    //      PREAMBLE
    //////////////////////////////////////////////////////////////////////////////////
    f_EUTRA_Init (c1);
    f_EUTRA_CellConfig_Def (eutra_Cell1);
    f_EUTRA_Preamble (eutra_Cell1, STATE2A_TESTLOOP_ModeA);
    // Bring UE to state 3
    ///////////////////////////////////////////////////////////////////////////////////
    //      Test Body
    //////////////////////////////////////////////////////////////////////////////////
    f_EUTRA_TestBody_Set(true);
    // Test body starts
    // E-UTRA radio bearer combination 5: SRB1 and SRB2 for DCCH + 2xAM DRB + 2xUM DRB
    f_GenericProcedure_12_1_1(eutra_Cell1, 2, 2);
    // E-UTRA radio bearer combination 8: SRB1 and SRB2 for DCCH + 3xAM DRB + 2xUM DRB
    f_GenericProcedure_12_1_1(eutra_Cell1, 3, 2);
    // E-UTRA radio bearer combination 11: SRB1 and SRB2 for DCCH + 4xAM DRB + 2xUM DRB
    f_GenericProcedure_12_1_1(eutra_Cell1, 4, 2);
    // E-UTRA radio bearer combination 12: SRB1 and SRB2 for DCCH + 5xAM DRB + 3xUM DRB
    f_GenericProcedure_12_1_1(eutra_Cell1, 5, 3);
    f_EUTRA_TestBody_Set(false);
    //test body ends
    ///////////////////////////////////////////////////////////////////////////////////
    //      Post Amble
    //////////////////////////////////////////////////////////////////////////////////
    
    //Switch off UE and expect a DETACH REQUEST message
    f_EUTRA_Postamble (eutra_Cell1, E1_IDLE);
  };

  function f_TC_12_2_4_EUTRA ( ) runs on EUTRA_PTC
  { /* DRB/12.2
       12.2.4 : Data transfer of E-UTRA radio bearer combination 13
    */
    
    ///////////////////////////////////////////////////////////////////////////////////
    //      PREAMBLE
    //////////////////////////////////////////////////////////////////////////////////
    f_EUTRA_Init (c1);
    f_EUTRA_CellConfig_Def (eutra_Cell1);
    f_EUTRA_Preamble (eutra_Cell1, STATE2A_TESTLOOP_ModeA);
    // Bring UE to state 3
    ///////////////////////////////////////////////////////////////////////////////////
    //      Test Body
    //////////////////////////////////////////////////////////////////////////////////
    f_EUTRA_TestBody_Set(true);
    // Test body starts
    // E-UTRA radio bearer combination 13: SRB1 and SRB2 for DCCH + 8xAM DRB
    f_GenericProcedure_12_1_1(eutra_Cell1, 8, 0);
    f_EUTRA_TestBody_Set(false);
    //test body ends
    ///////////////////////////////////////////////////////////////////////////////////
    //      Post Amble
    //////////////////////////////////////////////////////////////////////////////////
    
    //Switch off UE and expect a DETACH REQUEST message
    f_EUTRA_Postamble (eutra_Cell1, E1_IDLE);
  };
}
