module M3UA_Emulation_Test
{

//import from MTP3asp_PortType all;
import from MTP3asp_Types all;
import from BICC_Types all;
import from M3UA_Emulation all;
import from SCTPasp_PortType all;

modulepar
{
  SCTP_Association_Address tsp_address := { 0, "", 0, "" };
  // float tsp_serverWait := 5.0;
  // boolean tsp_serverTest := false;
}

type port MTP3asp_PT_Int message
{
  out  ASP_MTP3_TRANSFERreq;
  in ASP_MTP3_TRANSFERind;
} with {extension "internal"}

type component BICC_CT
{
  port MTP3asp_PT_Int BICC_MTP3_PORT;
}

type component MTC_CT
{
  var  BICC_CT vlc_BICC_COMPONENT_1;
  var  M3UA_CT vlc_M3UA_COMPONENT_1;
  port SCTPasp_PT SCTP_PORT;

//  var  BICC_CT vlc_BICC_COMPONENT_2;
//  port MTP3asp_PT M3UA_PORT;
}

function f_testconfig_bicc(SCTP_Association_Address pl_address) runs on MTC_CT
{
  vlc_BICC_COMPONENT_1 := BICC_CT.create;
  vlc_M3UA_COMPONENT_1 := M3UA_CT.create;
  connect(vlc_BICC_COMPONENT_1:BICC_MTP3_PORT,
          vlc_M3UA_COMPONENT_1:MTP3_SP_PORT);
  map(system:SCTP_PORT, vlc_M3UA_COMPONENT_1:SCTP_PORT);
  vlc_M3UA_COMPONENT_1.start(f_M3UA_Emulation(pl_address));
}

function f_testconfig_end_demo_bicc() runs on MTC_CT
{
  unmap(system:SCTP_PORT, vlc_M3UA_COMPONENT_1:SCTP_PORT);
  disconnect(vlc_BICC_COMPONENT_1:BICC_MTP3_PORT, vlc_M3UA_COMPONENT_1:MTP3_SP_PORT);
  vlc_M3UA_COMPONENT_1.stop;
}

template ASP_MTP3_TRANSFERind tr_ASP_MTP3_TRANSFERind_BICC :=
{ sio := {
    ni := '10'B,
    prio := ?,
    si := '1101'B
  },
  opc := ?,
  dpc := ?,
  sls := ?,
  data := ?
}

function f_init_BICC_bicc() runs on BICC_CT
{
  var PDU_BICC vl_PDU_BICC;
  var ASP_MTP3_TRANSFERind vl_ASP_MTP3_TRANSFERind;
  var ASP_MTP3_TRANSFERreq vl_ASP_MTP3_TRANSFERreq;
    
  vl_PDU_BICC := {
    BICC_GRA := {
      CIC := '00000000'O,
      MType := '00010111'B,
      var_part_ptr := 1,
      RngSts :=
      { range := '1F'O,
        status := ''O
      }
    }
  }

  vl_ASP_MTP3_TRANSFERreq := {
    sio := {
      ni := '10'B,
      prio := '00'B,
      si := '1101'B
    },
    opc := 115,
    dpc := 300,
    sls := 0,
    data := enc_PDU_BICC(vl_PDU_BICC)
  }
  
  timer T_Timer := 5.0;
  T_Timer.start;
  alt {
    [] BICC_MTP3_PORT.receive(tr_ASP_MTP3_TRANSFERind_BICC)
      -> value vl_ASP_MTP3_TRANSFERind {
      log("BICC_MTP3_PORT: received message: ", vl_ASP_MTP3_TRANSFERind);
      vl_PDU_BICC := dec_PDU_BICC(vl_ASP_MTP3_TRANSFERind.data);
      log("received BICC message: ", vl_PDU_BICC);
      setverdict(pass);
      BICC_MTP3_PORT.send(vl_ASP_MTP3_TRANSFERreq);
      T_Timer.stop;
    }
    [] BICC_MTP3_PORT.receive(ASP_MTP3_TRANSFERind : ?)
      -> value vl_ASP_MTP3_TRANSFERind {
      log("BICC_MTP3_PORT: received message: ", vl_ASP_MTP3_TRANSFERind);
      repeat;
    }
    [] BICC_MTP3_PORT.receive {
      setverdict(fail);
    }
    [] T_Timer.timeout {
      setverdict(fail);
    }
  }
  
  T_Timer.start;
  alt {
    [] BICC_MTP3_PORT.receive(tr_ASP_MTP3_TRANSFERind_BICC)
      -> value vl_ASP_MTP3_TRANSFERind {
      log("BICC_MTP3_PORT: received message: ", vl_ASP_MTP3_TRANSFERind);
      vl_PDU_BICC := dec_PDU_BICC(vl_ASP_MTP3_TRANSFERind.data);
      log("received BICC message: ", vl_PDU_BICC);
      repeat;
    }
    [] BICC_MTP3_PORT.receive(ASP_MTP3_TRANSFERind : ?)
      -> value vl_ASP_MTP3_TRANSFERind {
      log("BICC_MTP3_PORT: received message: ", vl_ASP_MTP3_TRANSFERind);
      repeat;
    }
    [] BICC_MTP3_PORT.receive {
    }
    [] T_Timer.timeout {
    }
  }

}

testcase tc_M3UA_demo_bicc() runs on MTC_CT
{
  f_testconfig_bicc(tsp_address);
  vlc_BICC_COMPONENT_1.start(f_init_BICC_bicc());
  vlc_BICC_COMPONENT_1.done;
  f_testconfig_end_demo_bicc();
}

}
