///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2000-2017 Ericsson Telecom AB
//
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// which accompanies this distribution, and is available at
// http://www.eclipse.org/legal/epl-v10.html
///////////////////////////////////////////////////////////////////////////////
//
//  File:         mtp3test.cc
//  Description:  basic test for MTP3asp_PT
//  Rev:          R12A
//  Prodnr:       CNL 113 337 
//  Updated:      2004.06.02
//  Contact:      http://ttcn.ericsson.se
 

module mtp3test
{

modulepar
{
  //mtp3test specific data:
  //OCT1n   MTP3_UserPart_SIO;
  MTP3_Field_sio MTP3_UserPart_SIO;
  integer MTP3_UserPart_OPC,
          MTP3_UserPart_DPC,
          MTP3_UserPart_SLS
};//modulepar 

import from MTP3asp_Types all;
import from MTP3asp_PortType all;

/*************************************
*   Components
**************************************/

/*
****************  1:      2: ************************
* MTP3UserPart * <---------> *   MTP3/M3UA in MSC   * 
****************   (MTP3port)************************
1: MTP3asp_PT MTP3_PCO  alias: e.g. CMGW6
 
*/

type record of MTP3UserPart_CT CompArray;

type component MTC_CT
{
  port MTP3asp_PT MTC_PCO;
  var  MTP3UserPart_CT  vc_MTP3UserPart_BSC1A;
  var  MTP3UserPart_CT  vc_MTP3UserPart_BSC1B;
  var  MTP3UserPart_CT  vc_MTP3UserPart_BSC1C;
  var  MTP3UserPart_CT  vc_MTP3UserPart_CMGW3;
  var  MTP3UserPart_CT  vc_MTP3UserPart_CMGW6;
  var  MTP3UserPart_CT  vc_MTP3UserPart_CMGW9;
  var  MTP3UserPart_CT  vc_compArray[6];
};

// Model of MSC:
type component MSC_SCT
{
  port MTP3asp_PT  BSC1A;
  port MTP3asp_PT  BSC1B;
  port MTP3asp_PT  BSC1C;   
  port MTP3asp_PT  CMGW3;
  port MTP3asp_PT  CMGW6;
  port MTP3asp_PT  CMGW9;
};

//Model of SS7 MTP3 User Part for Self Test. Only logs the messages
type component MTP3UserPart_CT
{
  var ASP_MTP3_TRANSFERind  v_MTP3_TRANSFERind;
  var ASP_MTP3_TRANSFERreq  v_MTP3_TRANSFERreq;
  port MTP3asp_PT           MTP3_PCO;
  // port ... to the upper layers
} // end component type definition

/*
function MTC_delay(integer time) runs on MTC_CT {
  timer t:=time;
  t.start;
  setverdict(none);
  alt{ []t.timeout {} }
 }
*/

function mtp3_selftest( ) runs on MTP3UserPart_CT 
{    
  timer t_Guard := 6.0;
  log( "mtp3_selftest started");
  t_Guard.start;
  setverdict(none);
  alt
  { 
    [] MTP3_PCO.receive ( ASP_MTP3_TRANSFERind:?)  -> value v_MTP3_TRANSFERind 
      {
        log("ASP_MTP3_TRANSFERind: received");
        setverdict(pass);
        repeat;
      } 
    [] MTP3_PCO.receive
      {
        log("Unknown signal received");
        setverdict(pass);
        repeat;
      }
    [] t_Guard.timeout 
      { log("timeout reached");}
  } //alt
  log("mtp3_selftest finished");
}

function f_init( ) runs on MTC_CT
{
  vc_MTP3UserPart_BSC1A := MTP3UserPart_CT.create;
  vc_MTP3UserPart_BSC1B := MTP3UserPart_CT.create;
  vc_MTP3UserPart_BSC1C := MTP3UserPart_CT.create;
  vc_MTP3UserPart_CMGW3 := MTP3UserPart_CT.create;
  vc_MTP3UserPart_CMGW6 := MTP3UserPart_CT.create;
  vc_MTP3UserPart_CMGW9 := MTP3UserPart_CT.create;

  map(vc_MTP3UserPart_BSC1A:MTP3_PCO,system:BSC1A);
  map(vc_MTP3UserPart_BSC1B:MTP3_PCO,system:BSC1B);
  map(vc_MTP3UserPart_BSC1C:MTP3_PCO,system:BSC1C);
  map(vc_MTP3UserPart_CMGW3:MTP3_PCO,system:CMGW3);
  map(vc_MTP3UserPart_CMGW6:MTP3_PCO,system:CMGW6);
  map(vc_MTP3UserPart_CMGW9:MTP3_PCO,system:CMGW9);

  log("tc_3 map is ready");
}

function f_start() runs on MTC_CT
{
  vc_MTP3UserPart_BSC1A.start( mtp3userpart_test() );
  vc_MTP3UserPart_BSC1B.start( mtp3userpart_test() );
  vc_MTP3UserPart_BSC1C.start( mtp3userpart_test() );
  vc_MTP3UserPart_CMGW3.start( mtp3userpart_test() );
  vc_MTP3UserPart_CMGW6.start( mtp3userpart_test() );
  vc_MTP3UserPart_CMGW9.start( mtp3userpart_test() );
}

function f_terminate() runs on MTC_CT
{
  all component.done;
  unmap(vc_MTP3UserPart_BSC1A:MTP3_PCO,system:BSC1A);
  unmap(vc_MTP3UserPart_BSC1B:MTP3_PCO,system:BSC1B);
  unmap(vc_MTP3UserPart_BSC1C:MTP3_PCO,system:BSC1C);
  unmap(vc_MTP3UserPart_CMGW3:MTP3_PCO,system:CMGW3);
  unmap(vc_MTP3UserPart_CMGW6:MTP3_PCO,system:CMGW6);
  unmap(vc_MTP3UserPart_CMGW9:MTP3_PCO,system:CMGW9);
}

function mtp3userpart_test( ) runs on MTP3UserPart_CT {
  timer t_Guard := 5.0;
  log( "mtp3userpart_test started");
  v_MTP3_TRANSFERreq := 
  {
    sio := MTP3_UserPart_SIO,
    opc := MTP3_UserPart_OPC,
    dpc := MTP3_UserPart_DPC,
    sls := 0,
    data:= '010203040506070809000102030405060708090000010203040506070809000000'O
  };
  MTP3_PCO.send( v_MTP3_TRANSFERreq );
  t_Guard.start;
  setverdict(none);
  alt 
  {
    [] MTP3_PCO.receive ( ASP_MTP3_TRANSFERind:? )  -> value v_MTP3_TRANSFERind
      {
        log("ASP_MTP3_TRANSFERind: received");
        setverdict(pass);
        repeat;
      } 
    [] MTP3_PCO.receive
      {
        log("Unknown signal received");
        setverdict(pass);
        repeat;
      }
    [] t_Guard.timeout
      {
        //setverdict(inconc);
        log("timeout reached");
      }
  } //alt
  log("mtp3userpart_test finished");
}

testcase tc_1() runs on MTC_CT system MSC_SCT
{
  log ("tc_1 started");
  var MTP3UserPart_CT vc_MTP3userpart;
  vc_MTP3userpart := MTP3UserPart_CT.create;
  map(vc_MTP3userpart:MTP3_PCO, system:CMGW6);
  log("map is ready");
  vc_MTP3userpart.start( mtp3_selftest() );
  //MTC_delay(6);
  vc_MTP3userpart.done;
  unmap(vc_MTP3userpart:MTP3_PCO, system:CMGW6);
  log ("tc_1 finished");
}

// TC2: Testcase sending one simple message "MTP-transfer-req" and waiting
testcase tc_2() runs on MTC_CT system MSC_SCT
{
  log ("tc_2 started");
  var MTP3UserPart_CT vc_MTP3userpart;  
  vc_MTP3userpart := MTP3UserPart_CT.create;
  map(vc_MTP3userpart:MTP3_PCO, system:CMGW6);
  log("map is ready");  
  vc_MTP3userpart.start( mtp3userpart_test() );
  //MTC_delay(6);  
  vc_MTP3userpart.done;
  unmap(vc_MTP3userpart:MTP3_PCO, system:CMGW6);
  log ("tc_2 finished");
}

testcase tc_3() runs on MTC_CT system MSC_SCT
{
  log ("tc_3 started");
  vc_MTP3UserPart_BSC1A := MTP3UserPart_CT.create;
  vc_MTP3UserPart_BSC1B := MTP3UserPart_CT.create;
  vc_MTP3UserPart_BSC1C := MTP3UserPart_CT.create;
  vc_MTP3UserPart_CMGW3 := MTP3UserPart_CT.create;
  vc_MTP3UserPart_CMGW6 := MTP3UserPart_CT.create;
  vc_MTP3UserPart_CMGW9 := MTP3UserPart_CT.create;
  
  map(vc_MTP3UserPart_BSC1A:MTP3_PCO,system:BSC1A);
  map(vc_MTP3UserPart_BSC1B:MTP3_PCO,system:BSC1B);
  map(vc_MTP3UserPart_BSC1C:MTP3_PCO,system:BSC1C);
  map(vc_MTP3UserPart_CMGW3:MTP3_PCO,system:CMGW3);
  map(vc_MTP3UserPart_CMGW6:MTP3_PCO,system:CMGW6);
  map(vc_MTP3UserPart_CMGW9:MTP3_PCO,system:CMGW9);
  
  log("tc_3 map is ready");  
  vc_MTP3UserPart_BSC1A.start( mtp3userpart_test() );
  vc_MTP3UserPart_BSC1B.start( mtp3userpart_test() );
  vc_MTP3UserPart_BSC1C.start( mtp3userpart_test() );
  vc_MTP3UserPart_CMGW3.start( mtp3userpart_test() );
  vc_MTP3UserPart_CMGW6.start( mtp3userpart_test() );
  vc_MTP3UserPart_CMGW9.start( mtp3userpart_test() );
  
  //MTC_delay(6);  
  all component.done;
  unmap(vc_MTP3UserPart_BSC1A:MTP3_PCO,system:BSC1A);
  unmap(vc_MTP3UserPart_BSC1B:MTP3_PCO,system:BSC1B);
  unmap(vc_MTP3UserPart_BSC1C:MTP3_PCO,system:BSC1C);
  unmap(vc_MTP3UserPart_CMGW3:MTP3_PCO,system:CMGW3);
  unmap(vc_MTP3UserPart_CMGW6:MTP3_PCO,system:CMGW6);
  unmap(vc_MTP3UserPart_CMGW9:MTP3_PCO,system:CMGW9); 
  log ("tc_3 finished"); 
} 

// tc_4 is the same as tc_3 but organized by arrays and cycles
testcase tc_4() runs on MTC_CT system MSC_SCT
{
  f_init();
  f_start();
  f_terminate();
}

testcase tc_5() runs on MTC_CT
{
  var ASP_MTP3_TRANSFERreq vl_MTP3_TRANSFERreq := 
  { sio := 
    { ni := '00'B,
      prio := '00'B,
      si := '0000'B
    },
    opc := 0,
    dpc := 0,
    sls := 0,
    data:= '010203040506070809000102030405060708090000010203040506070809000000'O
  };

  map(self:MTC_PCO,system:MTC_PCO);
  MTC_PCO.send(vl_MTP3_TRANSFERreq);
  MTC_PCO.receive;
  unmap(self:MTC_PCO,system:MTC_PCO);
}

control
{
  execute (tc_1());
}

}//module